From 9d263b5fbd646acc936e9f5d4af86a892c71182e Mon Sep 17 00:00:00 2001 From: RandomHashTags Date: Wed, 5 Aug 2026 02:05:52 -0500 Subject: [PATCH 1/2] use `Span` instead of `VLArray` --- .swift-version | 2 +- Package.swift | 8 --- .../extensions/InlineArrayExtensions.swift | 66 +++++++++---------- .../Destiny/extensions/StringExtensions.swift | 8 --- .../AbstractHTTPRequest+_Storage.swift | 17 +++-- Sources/Destiny/request/HTTPRequestLine.swift | 31 ++------- Sources/Destiny/routes/DynamicResponse.swift | 10 ++- .../routes/DynamicResponseProtocol.swift | 6 +- .../router/CompiledRouterStorage+Build.swift | 14 ++-- 9 files changed, 57 insertions(+), 105 deletions(-) delete mode 100644 Sources/Destiny/extensions/StringExtensions.swift diff --git a/.swift-version b/.swift-version index 4ac4fded..31b44b03 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -6.2.0 \ No newline at end of file +6.2.4 \ No newline at end of file diff --git a/Package.swift b/Package.swift index 46830dc8..2eaa6e5c 100644 --- a/Package.swift +++ b/Package.swift @@ -37,13 +37,6 @@ var pkgDependencies:[Package.Dependency] = [ .trait(name: "UnwrapSubtraction", condition: .when(traits: ["UnwrapSubtraction"])), .trait(name: "UnwrapArithmetic", condition: .when(traits: ["UnwrapArithmetic"])) ] - ), - - // Variable-length arrays - .package( - url: "https://github.com/RandomHashTags/swift-variablelengtharray", - from: "0.2.0", - traits: [] ) ] @@ -412,7 +405,6 @@ var targets = [ .product(name: "Logging", package: "swift-log", condition: .when(traits: ["Logging"])), .product(name: "MediaTypes", package: "swift-media-types", condition: .when(traits: ["MediaTypes"])), .product(name: "UnwrapArithmeticOperators", package: "swift-unwrap-arithmetic-operators"), - .product(name: "VariableLengthArray", package: "swift-variablelengtharray"), .product(name: "SwiftCompressionUtilities", package: "swift-compression", condition: .when(traits: ["Compression"])) ] ), diff --git a/Sources/Destiny/extensions/InlineArrayExtensions.swift b/Sources/Destiny/extensions/InlineArrayExtensions.swift index 41d1ae01..c1fdc7ba 100644 --- a/Sources/Destiny/extensions/InlineArrayExtensions.swift +++ b/Sources/Destiny/extensions/InlineArrayExtensions.swift @@ -1,33 +1,5 @@ import UnwrapArithmeticOperators -import VariableLengthArray - -// MARK: VLArray -extension VLArray where Element == UInt8 { - /// - Returns: A case-literal `String` initialized from `storage`. - /// - Warning: The returned `String` is the exact size of this `VLArray`! This function doesn't look for a null-terminator! - public func unsafeString() -> String { - return String.init(unsafeUninitializedCapacity: storage.count, initializingUTF8With: { - return $0.initialize(from: storage).index - }) - } - - /// Efficiently initializes a `String` from `storage`. - /// - /// - Returns: A case-literal `String` initialized from `storage` with start and end indexes. - /// - Warning: `endIndex` MUST be greater than `startIndex`. - public func unsafeString(startIndex: Int, endIndex: Int) -> String { - let count = endIndex -! startIndex - let slice = storage[startIndex.. String { - return self.span.withUnsafeBufferPointer { pointer in + return span.unsafeString() + } + + /// Efficiently initializes a `String` from `span`. + /// + /// - Returns: A case-literal `String` initialized from `span` with start and end indexes. + /// - Warning: `endIndex` MUST be greater than `startIndex`. + public func unsafeString(startIndex: Int, endIndex: Int) -> String { + return span.unsafeString(startIndex: startIndex, endIndex: endIndex) + } +} + +// MARK: HTTPSocketWritable +extension InlineArray: HTTPSocketWritable {} + + + + +// MARK: Span +extension Span { + /// Efficiently initializes a `String` from this span. + /// + /// - Returns: A case-literal `String`. + /// - Warning: The returned `String` is the exact size of this `Span`! This function doesn't look for a null-terminator! + public func unsafeString() -> String { + return self.withUnsafeBufferPointer { pointer in return String.init(unsafeUninitializedCapacity: pointer.count, initializingUTF8With: { return $0.initialize(from: pointer).index }) } } - /// Efficiently initializes a `String` from `span`. + /// Efficiently initializes a `String` from this span. /// - /// - Returns: A case-literal `String` initialized from `span` with start and end indexes. + /// - Returns: A case-literal `String` initialized from this span with start and end indexes. /// - Warning: `endIndex` MUST be greater than `startIndex`. public func unsafeString(startIndex: Int, endIndex: Int) -> String { - return self.span.withUnsafeBufferPointer { + return self.withUnsafeBufferPointer { let count = endIndex -! startIndex let slice = $0[startIndex..(_ closure: (consuming VLArray) throws(E) -> Void) rethrows { - try VLArray.create(string: self, closure) - } -} \ No newline at end of file diff --git a/Sources/Destiny/request/AbstractHTTPRequest+_Storage.swift b/Sources/Destiny/request/AbstractHTTPRequest+_Storage.swift index 0b94f572..5f1f937f 100644 --- a/Sources/Destiny/request/AbstractHTTPRequest+_Storage.swift +++ b/Sources/Destiny/request/AbstractHTTPRequest+_Storage.swift @@ -1,6 +1,5 @@ import UnwrapArithmeticOperators -import VariableLengthArray extension AbstractHTTPRequest { /// Underlying storage for the default request implementation. @@ -147,7 +146,7 @@ extension AbstractHTTPRequest._Storage { return methodString } requestLine!.method(buffer: buffer.buffer) { - methodString = $0.unsafeString() + methodString = $0 } return methodString! } @@ -160,21 +159,21 @@ extension AbstractHTTPRequest._Storage { if let path { return path } - requestLine!.path(buffer: buffer.buffer, { + requestLine!.path(buffer: buffer.buffer.span) { span in path = [String]() var startIndex = 0 - for i in $0.indices { - if $0.storage[i] == .forwardSlash { + for i in span.indices { + if span[i] == .forwardSlash { if startIndex < i { - path!.append($0.unsafeString(startIndex: startIndex, endIndex: i)) + path!.append(span.unsafeString(startIndex: startIndex, endIndex: i)) } startIndex = i +! 1 } } - if startIndex < $0.count { - path!.append($0.unsafeString(startIndex: startIndex, endIndex: $0.count)) + if startIndex < span.count { + path!.append(span.unsafeString(startIndex: startIndex, endIndex: span.count)) } - }) + } return path! } } diff --git a/Sources/Destiny/request/HTTPRequestLine.swift b/Sources/Destiny/request/HTTPRequestLine.swift index fe176cf6..0485c8ef 100644 --- a/Sources/Destiny/request/HTTPRequestLine.swift +++ b/Sources/Destiny/request/HTTPRequestLine.swift @@ -1,6 +1,5 @@ import UnwrapArithmeticOperators -import VariableLengthArray /// Default HTTP Request Line implementation that includes the request method, target and HTTP version. public struct HTTPRequestLine: Sendable, ~Copyable { @@ -38,35 +37,19 @@ public struct HTTPRequestLine: Sendable, ~Copyable { endIndex -! 9 } - public func path( - buffer: InlineArray, - _ closure: (consuming VLArray) -> Void + public func path( + buffer: Span, + _ closure: (Span) -> Void ) { - let pathCount = pathCount - withUnsafeTemporaryAllocation(of: UInt8.self, capacity: pathCount, { pathBuffer in - var offset = methodEndIndex +! 1 - if pathCount <= 128 { - for i in 0..(_storage: pathBuffer) - closure(pathArray) - }) + let offset = methodEndIndex +! 1 + closure(buffer.extracting(unchecked: offset..( buffer: InlineArray, - _ closure: (consuming VLArray) -> Void + _ closure: (String) -> Void ) { - VLArray.create(amount: methodEndIndex, initialize: { - buffer[unchecked: $0] - }, closure) + closure(buffer.unsafeString(startIndex: 0, endIndex: methodEndIndex)) } public func simd( diff --git a/Sources/Destiny/routes/DynamicResponse.swift b/Sources/Destiny/routes/DynamicResponse.swift index 77df4c32..7e9fe7c0 100644 --- a/Sources/Destiny/routes/DynamicResponse.swift +++ b/Sources/Destiny/routes/DynamicResponse.swift @@ -1,6 +1,4 @@ -import VariableLengthArray - #if hasFeature(Embedded) || EMBEDDED /// Default Dynamic Response implementation that builds an HTTP Message for dynamic requests. @@ -54,12 +52,12 @@ extension DynamicResponse { parameters[index] } - public mutating func setParameter(at index: Int, value: consuming VLArray) { - parameters[index] = value.unsafeString() + public mutating func setParameter(at index: Int, value: String) { + parameters[index] = value } - public mutating func appendParameter(value: consuming VLArray) { - parameters.append(value.unsafeString()) + public mutating func appendParameter(value: String) { + parameters.append(value) } public func yieldParameters(_ yield: (String) -> Void) { diff --git a/Sources/Destiny/routes/DynamicResponseProtocol.swift b/Sources/Destiny/routes/DynamicResponseProtocol.swift index b0b132af..3e727ff0 100644 --- a/Sources/Destiny/routes/DynamicResponseProtocol.swift +++ b/Sources/Destiny/routes/DynamicResponseProtocol.swift @@ -1,6 +1,4 @@ -import VariableLengthArray - /// Core protocol that builds a HTTP Message for dynamic routes before sending it to the client. public protocol DynamicResponseProtocol: HTTPSocketWritable, ~Copyable { /// - Parameters: @@ -10,10 +8,10 @@ public protocol DynamicResponseProtocol: HTTPSocketWritable, ~Copyable { mutating func setParameter( at index: Int, - value: consuming VLArray + value: String ) - mutating func appendParameter(value: consuming VLArray) + mutating func appendParameter(value: String) func yieldParameters(_ yield: (String) -> Void) diff --git a/Sources/DestinyMacros/router/CompiledRouterStorage+Build.swift b/Sources/DestinyMacros/router/CompiledRouterStorage+Build.swift index 91bc7905..cec87755 100644 --- a/Sources/DestinyMacros/router/CompiledRouterStorage+Build.swift +++ b/Sources/DestinyMacros/router/CompiledRouterStorage+Build.swift @@ -618,19 +618,15 @@ extension CompiledRouterStorage { err = error return } - pathAtIndex.inlineVLArray { - response.setParameter(at: index, value: $0) - } + response.setParameter(at: index, value: pathAtIndex) if responder.pathComponent(at: parameterIndex) == .catchall { do throws(DestinyError) { var i = parameterIndex+1 try request.forEachPath(offset: i) { path in - path.inlineVLArray { - if i < maximumParameters { - response.setParameter(at: i, value: $0) - } else { - response.appendParameter(value: $0) - } + if i < maximumParameters { + response.setParameter(at: i, value: path) + } else { + response.appendParameter(value: path) } i += 1 } From 4d02f257e8614a063f7d927c764b7f83c24fc7d5 Mon Sep 17 00:00:00 2001 From: RandomHashTags Date: Wed, 5 Aug 2026 02:07:21 -0500 Subject: [PATCH 2/2] remove `swift-variablelengtharray` dependency from Embedded package.swift --- Embedded/Package.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Embedded/Package.swift b/Embedded/Package.swift index de198626..5d404b1b 100644 --- a/Embedded/Package.swift +++ b/Embedded/Package.swift @@ -37,10 +37,7 @@ var pkgDependencies:[Package.Dependency] = [ .trait(name: "UnwrapSubtraction", condition: .when(traits: ["UnwrapSubtraction"])), .trait(name: "UnwrapArithmetic", condition: .when(traits: ["UnwrapArithmetic"])) ] - ), - - // Variable-length arrays - .package(url: "https://github.com/RandomHashTags/swift-variablelengtharray", from: "0.2.0", traits: []) + ) ] #if os(Linux)