Skip to content

Revert url template implementation #1267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions Benchmarks/Benchmarks/URL/BenchmarkURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,50 +231,4 @@ let benchmarks = {
}
}

Benchmark("URL-Template-parsing") { benchmark in
for _ in benchmark.scaledIterations {
blackHole(URL.Template("/api/{version}/accounts/{accountId}/transactions/{transactionId}{?expand*,fields*,embed*,format}")!)
blackHole(URL.Template("/special/{+a}/details")!)
blackHole(URL.Template("/documents/{documentId}{#section,paragraph}")!)
}
}

let templates = [
URL.Template("/var/{var}/who/{who}/x/{x}{?keys*,count*,list*,y}")!,
URL.Template("/special/{+keys}/details")!,
URL.Template("x/y/{#path:6}/here")!,
URL.Template("a/b{/var,x}/here")!,
URL.Template("a{?var,y}")!,
]

var variables: [URL.Template.VariableName: URL.Template.Value] = [
"count": ["one", "two", "three"],
"dom": ["example", "com"],
"dub": "me/too",
"hello": "Hello World!",
"half": "50%",
"var": "value",
"who": "fred",
"base": "http://example.com/home/",
"path": "/foo/bar",
"list": ["red", "green", "blue"],
"keys": [
"semi": ";",
"dot": ".",
"comma": ",",
],
"v": "6",
"x": "1024",
"y": "768",
"empty": "",
"empty_keys": [:],
]

Benchmark("URL-Template-expansion") { benchmark in
for _ in benchmark.scaledIterations {
for t in templates {
blackHole(URL(template: t, variables: variables))
}
}
}
}
8 changes: 1 addition & 7 deletions Sources/FoundationEssentials/URL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,4 @@ target_sources(FoundationEssentials PRIVATE
URL_Swift.swift
URLComponents.swift
URLComponents_ObjC.swift
URLParser.swift
URLTemplate_Expression.swift
URLTemplate_PercentEncoding.swift
URLTemplate_Substitution.swift
URLTemplate_Value.swift
URLTemplate_VariableName.swift
URLTemplate.swift)
URLParser.swift)
19 changes: 6 additions & 13 deletions Sources/FoundationEssentials/URL/URLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2023 - 2025 Apple Inc. and the Swift project authors
// Copyright (c) 2023 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -1229,8 +1229,8 @@ fileprivate struct URLComponentSet: OptionSet {
static let queryItem = URLComponentSet(rawValue: 1 << 7)
}

extension UTF8.CodeUnit {
fileprivate func isAllowedIn(_ component: URLComponentSet) -> Bool {
fileprivate extension UTF8.CodeUnit {
func isAllowedIn(_ component: URLComponentSet) -> Bool {
return allowedURLComponents & component.rawValue != 0
}

Expand Down Expand Up @@ -1260,7 +1260,7 @@ extension UTF8.CodeUnit {
// let queryItemAllowed = queryAllowed.subtracting(CharacterSet(charactersIn: "=&"))
// let fragmentAllowed = CharacterSet(charactersIn: pchar + "/?")
// ===------------------------------------------------------------------------------------=== //
fileprivate var allowedURLComponents: URLComponentSet.RawValue {
var allowedURLComponents: URLComponentSet.RawValue {
switch self {
case UInt8(ascii: "!"):
return 0b11110110
Expand Down Expand Up @@ -1311,8 +1311,8 @@ extension UTF8.CodeUnit {
}
}

/// Is the character in `unreserved + reserved` from RFC 3986.
internal var isValidURLCharacter: Bool {
// let urlAllowed = CharacterSet(charactersIn: unreserved + reserved)
var isValidURLCharacter: Bool {
guard self < 128 else { return false }
if self < 64 {
let allowed = UInt64(12682136387466559488)
Expand All @@ -1322,13 +1322,6 @@ extension UTF8.CodeUnit {
return (allowed & (UInt64(1) << (self - 64))) != 0
}
}

/// Is the character in `unreserved` from RFC 3986.
internal var isUnreservedURLCharacter: Bool {
guard self < 128 else { return false }
let allowed: UInt128 = 0x47fffffe87fffffe03ff600000000000
return allowed & (UInt128(1) << self) != 0
}
}

internal extension UInt8 {
Expand Down
185 changes: 0 additions & 185 deletions Sources/FoundationEssentials/URL/URLTemplate.swift

This file was deleted.

Loading