From 6ebb03bdd69500a311469f8c276147da7cfb1c21 Mon Sep 17 00:00:00 2001 From: RandomHashTags Date: Sun, 13 Oct 2024 22:13:29 -0500 Subject: [PATCH] removed `StaticString`'s `string` computed variable in favor of native `description` - native version is also faster --- Sources/HTMLKit/HTMLKit.swift | 90 ++--------------------------------- 1 file changed, 5 insertions(+), 85 deletions(-) diff --git a/Sources/HTMLKit/HTMLKit.swift b/Sources/HTMLKit/HTMLKit.swift index 0008797..e7d4fc4 100644 --- a/Sources/HTMLKit/HTMLKit.swift +++ b/Sources/HTMLKit/HTMLKit.swift @@ -9,95 +9,15 @@ import HTMLKitUtilities // MARK: StaticString equality public extension StaticString { - static func == (left: Self, right: String) -> Bool { left.string == right } - - static func == (left: Self, right: Self) -> Bool { left.string == right.string } - static func != (left: Self, right: Self) -> Bool { left.string != right.string } - var string : String { - withUTF8Buffer { - String(decoding: $0, as: UTF8.self) - } - } - /*func string(with replacements: [String]) -> String { - return withUTF8Buffer { p in - let values = p.split(separator: 96) - let last:Int = values.count-1 - var amount:Int = p.count - last - for i in 0.. = .allocate(capacity: amount) - var new_index:Int = 0 - for index in 0...SubSequence = values[index] - for i in 0.. Bool { left.description == right } + + static func == (left: Self, right: Self) -> Bool { left.description == right.description } + static func != (left: Self, right: Self) -> Bool { left.description != right.description } } public extension String { - static func == (left: Self, right: StaticString) -> Bool { left == right.string } + static func == (left: Self, right: StaticString) -> Bool { left == right.description } } -/* -// MARK: DynamicString -public struct DynamicString { - public let string:StaticString - public let values:[String] - - public init(string: StaticString, values: [String]) { - self.string = string - self.values = values - } - - public var test : String { - return string.string - } -}*/ - -/* -package struct NonCopyableString : ~Copyable { - private let storage:UnsafeMutableBufferPointer - - package init(capacity: Int) { - storage = .allocate(capacity: capacity) - } - package init(_ string: String) { - storage = .allocate(capacity: string.count) - for i in 0.. UInt8 { - get { - storage[index] - } - set { - storage[index] = newValue - } - } - - package var count : Int { storage.count } - package var isEmpty : Bool { storage.isEmpty } - package var string : String { String(decoding: storage, as: UTF8.self) } - - deinit { - storage.deinitialize() - storage.deallocate() - } -}*/ - @freestanding(expression) public macro escapeHTML(_ innerHTML: T...) -> T = #externalMacro(module: "HTMLKitMacros", type: "HTMLElement")