mirror of
https://github.com/apple/swift-http-types
synced 2026-11-25 04:47:48 +00:00
Merge pull request #44 from Joannis/jo/http-fields-dictionary-literal
Optimise initialization of HTTPFields through Dictionary Literal
This commit is contained in:
4 files changed
+52
No files matched your search
@@ -0,0 +1,8 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/configuration/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
@@ -0,0 +1,16 @@
|
||||
import HTTPTypes
|
||||
import Benchmark
|
||||
|
||||
let benchmarks = {
|
||||
Benchmark(
|
||||
"Initialize HTTPFields from Dictionary Literal"
|
||||
) { benchmark in
|
||||
let fiels: HTTPFields = [
|
||||
.contentType: "application/json",
|
||||
.contentLength: "42",
|
||||
.connection: "keep-alive",
|
||||
.accept: "application/json",
|
||||
.acceptEncoding: "gzip, deflate, br",
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// swift-tools-version: 5.7.1
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "Benchmarks",
|
||||
platforms: [
|
||||
.macOS(.v13)
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../"),
|
||||
.package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.22.1"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "Benchmarks",
|
||||
dependencies: [
|
||||
.product(name: "Benchmark", package: "package-benchmark"),
|
||||
.product(name: "HTTPTypes", package: "swift-http-types"),
|
||||
],
|
||||
path: "Benchmarks/HTTPFieldsBenchmarks",
|
||||
plugins: [
|
||||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark")
|
||||
]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -280,6 +280,7 @@ public struct HTTPFields: Sendable, Hashable {
|
||||
|
||||
extension HTTPFields: ExpressibleByDictionaryLiteral {
|
||||
public init(dictionaryLiteral elements: (HTTPField.Name, String)...) {
|
||||
self.reserveCapacity(elements.count)
|
||||
for (name, value) in elements {
|
||||
precondition(!name.isPseudo, "Pseudo header field \"\(name)\" disallowed")
|
||||
self._storage.append(field: HTTPField(name: name, value: value))
|
||||
|
||||
Reference in new issue
Block a user