Skip to content

Commit

Permalink
removed StaticString's string computed variable in favor of nativ…
Browse files Browse the repository at this point in the history
…e `description`

- native version is also faster
  • Loading branch information
RandomHashTags committed Oct 14, 2024
1 parent db132d4 commit 6ebb03b
Showing 1 changed file with 5 additions and 85 deletions.
90 changes: 5 additions & 85 deletions Sources/HTMLKit/HTMLKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<values.count-1 {
amount += replacements[i].count
}
let buffer:UnsafeMutableBufferPointer<UInt8> = .allocate(capacity: amount)
var new_index:Int = 0
for index in 0..<values.count {
let value:UnsafeBufferPointer<UInt8>.SubSequence = values[index]
for i in 0..<value.count {
buffer[new_index] = value[value.index(value.startIndex, offsetBy: i)]
new_index += 1
}
if index != last {
for char in replacements[index] {
buffer[new_index] = char.asciiValue!
new_index += 1
}
}
}
return String(decoding: buffer, as: UTF8.self)
}
}*/
static func == (left: Self, right: String) -> 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<UInt8>

package init(capacity: Int) {
storage = .allocate(capacity: capacity)
}
package init(_ string: String) {
storage = .allocate(capacity: string.count)
for i in 0..<string.count {
storage[i] = string[string.index(string.startIndex, offsetBy: i)].asciiValue!
}
}

package subscript(_ index: Int) -> 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<T: ExpressibleByStringLiteral>(_ innerHTML: T...) -> T = #externalMacro(module: "HTMLKitMacros", type: "HTMLElement")

Expand Down

0 comments on commit 6ebb03b

Please sign in to comment.