diff --git a/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift b/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift index d01659877..26bdc8582 100644 --- a/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift +++ b/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift @@ -15,11 +15,11 @@ import Benchmark import HTTPTypes import Hummingbird -import NIOEmbedded -import NIOHTTPTypes -@_spi(Internal) import HummingbirdCore +import HummingbirdCore import Logging import NIOCore +import NIOEmbedded +import NIOHTTPTypes import NIOPosix /// Implementation of a basic request context that supports everything the Hummingbird library needs diff --git a/Sources/Hummingbird/Router/EndpointResponder.swift b/Sources/Hummingbird/Router/EndpointResponder.swift index b7495e069..ef84c7d38 100644 --- a/Sources/Hummingbird/Router/EndpointResponder.swift +++ b/Sources/Hummingbird/Router/EndpointResponder.swift @@ -15,13 +15,15 @@ import HTTPTypes /// Stores endpoint responders for each HTTP method +@usableFromInline struct EndpointResponders: Sendable { init(path: String) { self.path = path self.methods = [:] } - public func getResponder(for method: HTTPRequest.Method) -> (any HTTPResponder)? { + @inlinable + public func getResponder(for method: __shared HTTPRequest.Method) -> (any HTTPResponder)? { return self.methods[method] } @@ -41,6 +43,9 @@ struct EndpointResponders: Sendable { } } + @usableFromInline var methods: [HTTPRequest.Method: any HTTPResponder] + + @usableFromInline var path: String } diff --git a/Sources/Hummingbird/Router/RouterResponder.swift b/Sources/Hummingbird/Router/RouterResponder.swift index 83945ce33..07257af4b 100644 --- a/Sources/Hummingbird/Router/RouterResponder.swift +++ b/Sources/Hummingbird/Router/RouterResponder.swift @@ -15,8 +15,13 @@ import NIOCore public struct RouterResponder: HTTPResponder { + @usableFromInline let trie: RouterTrie> + + @usableFromInline let notFoundResponder: any HTTPResponder + + @usableFromInline let options: RouterOptions init( @@ -33,6 +38,7 @@ public struct RouterResponder: HTTPResponder { /// Respond to request by calling correct handler /// - Parameter request: HTTP request /// - Returns: EventLoopFuture that will be fulfilled with the Response + @inlinable public func respond(to request: Request, context: Context) async throws -> Response { let path: String if self.options.contains(.caseInsensitive) { diff --git a/Sources/Hummingbird/Router/Trie/RouterTrie.swift b/Sources/Hummingbird/Router/Trie/RouterTrie.swift index be93c497f..313374009 100644 --- a/Sources/Hummingbird/Router/Trie/RouterTrie.swift +++ b/Sources/Hummingbird/Router/Trie/RouterTrie.swift @@ -56,14 +56,14 @@ struct Trie: Sendable { init() {} } -@_spi(Internal) public final class RouterTrie: Sendable { +@_documentation(visibility: internal) +public final class RouterTrie: Sendable { @usableFromInline let trie: Trie @usableFromInline let values: [Value?] - @inlinable @_spi(Internal) public init(base: RouterPathTrieBuilder) { var trie = Trie() var values: [Value?] = [] diff --git a/Sources/Hummingbird/Router/Trie/Trie+resolve.swift b/Sources/Hummingbird/Router/Trie/Trie+resolve.swift index 7439a75e4..383f63ae2 100644 --- a/Sources/Hummingbird/Router/Trie/Trie+resolve.swift +++ b/Sources/Hummingbird/Router/Trie/Trie+resolve.swift @@ -17,7 +17,7 @@ import NIOCore extension RouterTrie { /// Resolve a path to a `Value` if available @inlinable - @_spi(Internal) public func resolve(_ path: String) -> (value: Value, parameters: Parameters)? { + public func resolve(_ path: String) -> (value: Value, parameters: Parameters)? { let pathComponents = path.split(separator: "/", omittingEmptySubsequences: true) var pathComponentsIterator = pathComponents.makeIterator() var parameters = Parameters() diff --git a/Sources/Hummingbird/Router/Trie/Trie+serialize.swift b/Sources/Hummingbird/Router/Trie/Trie+serialize.swift index 4fe1dbae7..9f0bad2d3 100644 --- a/Sources/Hummingbird/Router/Trie/Trie+serialize.swift +++ b/Sources/Hummingbird/Router/Trie/Trie+serialize.swift @@ -15,7 +15,6 @@ import NIOCore extension RouterTrie { - @inlinable static func serialize( _ node: RouterPathTrieBuilder.Node, trie: inout Trie, @@ -82,7 +81,6 @@ extension RouterTrie { trie.nodes[nodeIndex].nextSiblingNodeIndex = trie.nodes.count } - @inlinable static func serializeChildren( of node: RouterPathTrieBuilder.Node, trie: inout Trie, @@ -95,7 +93,6 @@ extension RouterTrie { } } - @inlinable internal static func highestPriorityFirst(lhs: RouterPathTrieBuilder.Node, rhs: RouterPathTrieBuilder.Node) -> Bool { lhs.key.priority > rhs.key.priority } diff --git a/Sources/Hummingbird/Router/TrieRouter.swift b/Sources/Hummingbird/Router/TrieRouter.swift index 71ef6b378..03b865115 100644 --- a/Sources/Hummingbird/Router/TrieRouter.swift +++ b/Sources/Hummingbird/Router/TrieRouter.swift @@ -19,7 +19,7 @@ import HummingbirdCore @usableFromInline var root: Node - public init() { + @_spi(Internal) public init() { self.root = Node(key: .null, output: nil) } @@ -28,7 +28,7 @@ import HummingbirdCore /// - entry: Path for entry /// - value: Value to add to this path if one does not exist already /// - onAdd: How to edit the value at this path - public func addEntry(_ entry: RouterPath, value: @autoclosure () -> Value, onAdd: (Node) -> Void = { _ in }) { + @_spi(Internal) public func addEntry(_ entry: RouterPath, value: @autoclosure () -> Value, onAdd: (Node) -> Void = { _ in }) { var node = self.root for key in entry { node = node.addChild(key: key, output: nil) @@ -51,13 +51,10 @@ import HummingbirdCore /// Trie Node. Each node represents one component of a URI path @_spi(Internal) public final class Node { - @usableFromInline let key: RouterPath.Element - @usableFromInline var children: [Node] - @usableFromInline var value: Value? init(key: RouterPath.Element, output: Value?) { diff --git a/Tests/HummingbirdTests/TrieRouterTests.swift b/Tests/HummingbirdTests/TrieRouterTests.swift index 60b44515d..46c4134df 100644 --- a/Tests/HummingbirdTests/TrieRouterTests.swift +++ b/Tests/HummingbirdTests/TrieRouterTests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -@_spi(Internal) import Hummingbird +@testable @_spi(Internal) import Hummingbird import XCTest class TrieRouterTests: XCTestCase {