From 3bf70f6f28f6011a742a2db38be529caf8a68aaf Mon Sep 17 00:00:00 2001 From: Alfons Hoogervorst Date: Tue, 15 Aug 2023 11:34:39 -0300 Subject: [PATCH 1/4] Allow conversions UUID <-> UInt128 --- Sources/UInt128+UUID.swift | 52 ++++++++++++++++++ Sources/UUID+UInt128.swift | 54 +++++++++++++++++++ .../UInt128PerformanceTests.swift | 14 +++++ Tests/UInt128Tests/UInt128Tests.swift | 19 +++++++ UInt128.xcodeproj/project.pbxproj | 20 +++++++ 5 files changed, 159 insertions(+) create mode 100644 Sources/UInt128+UUID.swift create mode 100644 Sources/UUID+UInt128.swift diff --git a/Sources/UInt128+UUID.swift b/Sources/UInt128+UUID.swift new file mode 100644 index 0000000..241bca6 --- /dev/null +++ b/Sources/UInt128+UUID.swift @@ -0,0 +1,52 @@ +// +// UInt128+UUID.swift +// UInt128 +// +// Created by Alfons Hoogervorst on 15/08/2023. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + +extension UInt128 { + + /// Creates a UInt128 from a UUID. Since a UUID is always 128 bits, + /// no truncation is needed. + public init(uuid: UUID) { + + func byte(_ val: UInt8, nr: Int) -> UInt64 { + let result = UInt64(integerLiteral: UInt64(val)) + return result << (nr * 8) + } + + let val = uuid.uuid + let lowerBits: UInt64 = byte(val.0, nr: 0) | + byte(val.1, nr: 1) | + byte(val.2, nr: 2) | + byte(val.3, nr: 3) | + byte(val.4, nr: 4) | + byte(val.5, nr: 5) | + byte(val.6, nr: 6) | + byte(val.7, nr: 7) + let upperBits: UInt64 = byte(val.8, nr: 0) | + byte(val.9, nr: 1) | + byte(val.10, nr: 2) | + byte(val.11, nr: 3) | + byte(val.12, nr: 4) | + byte(val.13, nr: 5) | + byte(val.14, nr: 6) | + byte(val.15, nr: 7) + self = .init(upperBits: upperBits, lowerBits: lowerBits) + } + +} diff --git a/Sources/UUID+UInt128.swift b/Sources/UUID+UInt128.swift new file mode 100644 index 0000000..97cc62e --- /dev/null +++ b/Sources/UUID+UInt128.swift @@ -0,0 +1,54 @@ +// +// UUID+UInt128.swift +// UInt128 +// +// Created by Alfons Hoogervorst on 15/08/2023. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import Foundation + + +extension UUID { + + /// Creates a UUID representation of a UInt128. Since a UUID is always + /// 128 bits, no truncation occurs. + public init(_ longInt: UInt128) { + + func byte(_ nr: Int) -> UInt8 { + let bits = (16 - (16 - nr)) * 8 + return UInt8((longInt >> bits) & 0xFF) + } + + let val: uuid_t = ( + byte(0), + byte(1), + byte(2), + byte(3), + byte(4), + byte(5), + byte(6), + byte(7), + byte(8), + byte(9), + byte(10), + byte(11), + byte(12), + byte(13), + byte(14), + byte(15) + ) + self = .init(uuid: val) + } + +} diff --git a/Tests/UInt128Tests/UInt128PerformanceTests.swift b/Tests/UInt128Tests/UInt128PerformanceTests.swift index a0d0910..bf38c56 100644 --- a/Tests/UInt128Tests/UInt128PerformanceTests.swift +++ b/Tests/UInt128Tests/UInt128PerformanceTests.swift @@ -40,4 +40,18 @@ final class CustomStringConvertiblePerformanceTests: XCTestCase { _ = UInt128("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")! } } + +} + +final class UUIDConvertibalePerformanceTests: XCTestCase { + + func testUUIDPlus() { + let uuid = UUID(uuidString: "1F349019-F3F5-489F-85F5-9CD214D6BD69")! + let options = XCTMeasureOptions() + options.iterationCount = 1000 + self.measure(options: options) { + _ = UInt128(uuid: uuid) + } + } + } diff --git a/Tests/UInt128Tests/UInt128Tests.swift b/Tests/UInt128Tests/UInt128Tests.swift index 78941e8..b77a4ed 100644 --- a/Tests/UInt128Tests/UInt128Tests.swift +++ b/Tests/UInt128Tests/UInt128Tests.swift @@ -1413,3 +1413,22 @@ class FloatingPointInterworkingTests: XCTestCase { } } } + +class UUIDTests: XCTestCase { + func testConvertUUID() { + let uuid = UUID(uuidString: "1F349019-F3F5-489F-85F5-9CD214D6BD69")! + let uint128 = UInt128(uuid: uuid) + let uuid128 = UUID(uint128) + XCTAssertEqual(uuid128, uuid) + + let uuid0 = UUID(uuidString: "00000000-0000-0000-0000-000000000000")! + let uint1280 = UInt128(uuid: uuid0) + let uuid1280 = UUID(uint1280) + XCTAssertEqual(uuid1280, uuid0) + + let uuidf = UUID(uuidString: "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF")! + let uint128f = UInt128(uuid: uuidf) + let uuid128f = UUID(uint128f) + XCTAssertEqual(uuid128f, uuidf) + } +} diff --git a/UInt128.xcodeproj/project.pbxproj b/UInt128.xcodeproj/project.pbxproj index 84a8750..8f861fe 100644 --- a/UInt128.xcodeproj/project.pbxproj +++ b/UInt128.xcodeproj/project.pbxproj @@ -13,6 +13,14 @@ 481A30BA1F02FC6600C4438A /* UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_8 /* UInt128.swift */; }; 481A30BB1F02FC6600C4438A /* UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_8 /* UInt128.swift */; }; 482193E72A20168800B90A8D /* UInt128PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 482193E62A20168800B90A8D /* UInt128PerformanceTests.swift */; }; + 867706002A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; + 867706012A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; + 867706022A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; + 867706032A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; + 867706052A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; + 867706062A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; + 867706072A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; + 867706082A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; OBJ_21 /* UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_8 /* UInt128.swift */; }; OBJ_28 /* UInt128Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* UInt128Tests.swift */; }; OBJ_30 /* UInt128.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* UInt128.framework */; }; @@ -48,6 +56,8 @@ 481A30AF1F02FB9F00C4438A /* UInt128.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UInt128.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 482193E62A20168800B90A8D /* UInt128PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UInt128PerformanceTests.swift; sourceTree = ""; }; 48389B601EDB9F78008C1177 /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UUID+UInt128.swift"; sourceTree = ""; }; + 867706042A8BB44300D09D91 /* UInt128+UUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt128+UUID.swift"; sourceTree = ""; }; OBJ_11 /* UInt128Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInt128Tests.swift; sourceTree = ""; }; OBJ_14 /* UInt128.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = UInt128.framework; sourceTree = BUILT_PRODUCTS_DIR; }; OBJ_15 /* UInt128Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = UInt128Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -134,6 +144,8 @@ isa = PBXGroup; children = ( OBJ_8 /* UInt128.swift */, + 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */, + 867706042A8BB44300D09D91 /* UInt128+UUID.swift */, ); path = Sources; sourceTree = SOURCE_ROOT; @@ -326,6 +338,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( + 867706002A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, + 867706052A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, 167CA9BD1EFCF3E50091689C /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -334,6 +348,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 867706022A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, + 867706072A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, 481A30BA1F02FC6600C4438A /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -342,6 +358,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 867706032A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, + 867706082A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, 481A30BB1F02FC6600C4438A /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -350,6 +368,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( + 867706012A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, + 867706062A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, OBJ_21 /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From d164aab1f437acbdf952c323cdf1f37b50ee912a Mon Sep 17 00:00:00 2001 From: Alfons Hoogervorst Date: Tue, 15 Aug 2023 15:11:53 -0300 Subject: [PATCH 2/4] Optimize for speed --- Sources/UInt128+UUID.swift | 38 +++++++++++++++--------------------- Sources/UUID+UInt128.swift | 40 +++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/Sources/UInt128+UUID.swift b/Sources/UInt128+UUID.swift index 241bca6..afcbfcf 100644 --- a/Sources/UInt128+UUID.swift +++ b/Sources/UInt128+UUID.swift @@ -23,29 +23,23 @@ extension UInt128 { /// Creates a UInt128 from a UUID. Since a UUID is always 128 bits, /// no truncation is needed. public init(uuid: UUID) { - - func byte(_ val: UInt8, nr: Int) -> UInt64 { - let result = UInt64(integerLiteral: UInt64(val)) - return result << (nr * 8) - } - let val = uuid.uuid - let lowerBits: UInt64 = byte(val.0, nr: 0) | - byte(val.1, nr: 1) | - byte(val.2, nr: 2) | - byte(val.3, nr: 3) | - byte(val.4, nr: 4) | - byte(val.5, nr: 5) | - byte(val.6, nr: 6) | - byte(val.7, nr: 7) - let upperBits: UInt64 = byte(val.8, nr: 0) | - byte(val.9, nr: 1) | - byte(val.10, nr: 2) | - byte(val.11, nr: 3) | - byte(val.12, nr: 4) | - byte(val.13, nr: 5) | - byte(val.14, nr: 6) | - byte(val.15, nr: 7) + let lowerBits: UInt64 = UInt64(val.0) << (0 * 8) | + UInt64(val.1) << (1 * 8) | + UInt64(val.2) << (2 * 8) | + UInt64(val.3) << (3 * 8) | + UInt64(val.4) << (4 * 8) | + UInt64(val.5) << (5 * 8) | + UInt64(val.6) << (6 * 8) | + UInt64(val.7) << (7 * 8) + let upperBits: UInt64 = UInt64(val.8) << (0 * 8) | + UInt64(val.9) << (1 * 8) | + UInt64(val.10) << (2 * 8) | + UInt64(val.11) << (3 * 8) | + UInt64(val.12) << (4 * 8) | + UInt64(val.13) << (5 * 8) | + UInt64(val.14) << (6 * 8) | + UInt64(val.15) << (7 * 8) self = .init(upperBits: upperBits, lowerBits: lowerBits) } diff --git a/Sources/UUID+UInt128.swift b/Sources/UUID+UInt128.swift index 97cc62e..2db3356 100644 --- a/Sources/UUID+UInt128.swift +++ b/Sources/UUID+UInt128.swift @@ -24,29 +24,25 @@ extension UUID { /// Creates a UUID representation of a UInt128. Since a UUID is always /// 128 bits, no truncation occurs. public init(_ longInt: UInt128) { - - func byte(_ nr: Int) -> UInt8 { - let bits = (16 - (16 - nr)) * 8 - return UInt8((longInt >> bits) & 0xFF) - } - + let lowerBits = longInt.value.lowerBits + let upperBita = longInt.value.upperBits let val: uuid_t = ( - byte(0), - byte(1), - byte(2), - byte(3), - byte(4), - byte(5), - byte(6), - byte(7), - byte(8), - byte(9), - byte(10), - byte(11), - byte(12), - byte(13), - byte(14), - byte(15) + UInt8((lowerBits >> (0 * 8)) & 0xFF), + UInt8((lowerBits >> (1 * 8)) & 0xFF), + UInt8((lowerBits >> (2 * 8)) & 0xFF), + UInt8((lowerBits >> (3 * 8)) & 0xFF), + UInt8((lowerBits >> (4 * 8)) & 0xFF), + UInt8((lowerBits >> (5 * 8)) & 0xFF), + UInt8((lowerBits >> (6 * 8)) & 0xFF), + UInt8((lowerBits >> (7 * 8)) & 0xFF), + UInt8((upperBita >> (0 * 8)) & 0xFF), + UInt8((upperBita >> (1 * 8)) & 0xFF), + UInt8((upperBita >> (2 * 8)) & 0xFF), + UInt8((upperBita >> (3 * 8)) & 0xFF), + UInt8((upperBita >> (4 * 8)) & 0xFF), + UInt8((upperBita >> (5 * 8)) & 0xFF), + UInt8((upperBita >> (6 * 8)) & 0xFF), + UInt8((upperBita >> (7 * 8)) & 0xFF) ) self = .init(uuid: val) } From 06a88b94c6ed66001f67f32126509f5c0c029371 Mon Sep 17 00:00:00 2001 From: Alfons Hoogervorst Date: Wed, 16 Aug 2023 05:56:56 -0300 Subject: [PATCH 3/4] Move new files to proper folder. Test should work now from command line and Xcode. --- Sources/{ => UInt128}/UInt128+UUID.swift | 0 Sources/{ => UInt128}/UUID+UInt128.swift | 0 UInt128.xcodeproj/project.pbxproj | 40 ++++++++++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) rename Sources/{ => UInt128}/UInt128+UUID.swift (100%) rename Sources/{ => UInt128}/UUID+UInt128.swift (100%) diff --git a/Sources/UInt128+UUID.swift b/Sources/UInt128/UInt128+UUID.swift similarity index 100% rename from Sources/UInt128+UUID.swift rename to Sources/UInt128/UInt128+UUID.swift diff --git a/Sources/UUID+UInt128.swift b/Sources/UInt128/UUID+UInt128.swift similarity index 100% rename from Sources/UUID+UInt128.swift rename to Sources/UInt128/UUID+UInt128.swift diff --git a/UInt128.xcodeproj/project.pbxproj b/UInt128.xcodeproj/project.pbxproj index 8f861fe..9d75f90 100644 --- a/UInt128.xcodeproj/project.pbxproj +++ b/UInt128.xcodeproj/project.pbxproj @@ -13,14 +13,14 @@ 481A30BA1F02FC6600C4438A /* UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_8 /* UInt128.swift */; }; 481A30BB1F02FC6600C4438A /* UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_8 /* UInt128.swift */; }; 482193E72A20168800B90A8D /* UInt128PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 482193E62A20168800B90A8D /* UInt128PerformanceTests.swift */; }; - 867706002A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; - 867706012A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; - 867706022A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; - 867706032A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */; }; - 867706052A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; - 867706062A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; - 867706072A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; - 867706082A8BB44300D09D91 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 867706042A8BB44300D09D91 /* UInt128+UUID.swift */; }; + 8609A4172A8CC63A00539492 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4152A8CC63A00539492 /* UInt128+UUID.swift */; }; + 8609A4182A8CC63A00539492 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4152A8CC63A00539492 /* UInt128+UUID.swift */; }; + 8609A4192A8CC63A00539492 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4152A8CC63A00539492 /* UInt128+UUID.swift */; }; + 8609A41A2A8CC63A00539492 /* UInt128+UUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4152A8CC63A00539492 /* UInt128+UUID.swift */; }; + 8609A41B2A8CC63A00539492 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4162A8CC63A00539492 /* UUID+UInt128.swift */; }; + 8609A41C2A8CC63A00539492 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4162A8CC63A00539492 /* UUID+UInt128.swift */; }; + 8609A41D2A8CC63A00539492 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4162A8CC63A00539492 /* UUID+UInt128.swift */; }; + 8609A41E2A8CC63A00539492 /* UUID+UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8609A4162A8CC63A00539492 /* UUID+UInt128.swift */; }; OBJ_21 /* UInt128.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_8 /* UInt128.swift */; }; OBJ_28 /* UInt128Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_11 /* UInt128Tests.swift */; }; OBJ_30 /* UInt128.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = OBJ_14 /* UInt128.framework */; }; @@ -56,8 +56,8 @@ 481A30AF1F02FB9F00C4438A /* UInt128.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UInt128.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 482193E62A20168800B90A8D /* UInt128PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UInt128PerformanceTests.swift; sourceTree = ""; }; 48389B601EDB9F78008C1177 /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UUID+UInt128.swift"; sourceTree = ""; }; - 867706042A8BB44300D09D91 /* UInt128+UUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UInt128+UUID.swift"; sourceTree = ""; }; + 8609A4152A8CC63A00539492 /* UInt128+UUID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UInt128+UUID.swift"; path = "UInt128/UInt128+UUID.swift"; sourceTree = ""; }; + 8609A4162A8CC63A00539492 /* UUID+UInt128.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UUID+UInt128.swift"; path = "UInt128/UUID+UInt128.swift"; sourceTree = ""; }; OBJ_11 /* UInt128Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UInt128Tests.swift; sourceTree = ""; }; OBJ_14 /* UInt128.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = UInt128.framework; sourceTree = BUILT_PRODUCTS_DIR; }; OBJ_15 /* UInt128Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; path = UInt128Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -144,8 +144,8 @@ isa = PBXGroup; children = ( OBJ_8 /* UInt128.swift */, - 867705FF2A8BAD0A00D09D91 /* UUID+UInt128.swift */, - 867706042A8BB44300D09D91 /* UInt128+UUID.swift */, + 8609A4152A8CC63A00539492 /* UInt128+UUID.swift */, + 8609A4162A8CC63A00539492 /* UUID+UInt128.swift */, ); path = Sources; sourceTree = SOURCE_ROOT; @@ -338,8 +338,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( - 867706002A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, - 867706052A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, + 8609A4172A8CC63A00539492 /* UInt128+UUID.swift in Sources */, + 8609A41B2A8CC63A00539492 /* UUID+UInt128.swift in Sources */, 167CA9BD1EFCF3E50091689C /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -348,8 +348,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 867706022A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, - 867706072A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, + 8609A4192A8CC63A00539492 /* UInt128+UUID.swift in Sources */, + 8609A41D2A8CC63A00539492 /* UUID+UInt128.swift in Sources */, 481A30BA1F02FC6600C4438A /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -358,8 +358,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 867706032A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, - 867706082A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, + 8609A41A2A8CC63A00539492 /* UInt128+UUID.swift in Sources */, + 8609A41E2A8CC63A00539492 /* UUID+UInt128.swift in Sources */, 481A30BB1F02FC6600C4438A /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -368,8 +368,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 0; files = ( - 867706012A8BAD0A00D09D91 /* UUID+UInt128.swift in Sources */, - 867706062A8BB44300D09D91 /* UInt128+UUID.swift in Sources */, + 8609A4182A8CC63A00539492 /* UInt128+UUID.swift in Sources */, + 8609A41C2A8CC63A00539492 /* UUID+UInt128.swift in Sources */, OBJ_21 /* UInt128.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From b2e067960b1a87aadac019e1ee5cac9deb30d229 Mon Sep 17 00:00:00 2001 From: Alfons Hoogervorst Date: Wed, 16 Aug 2023 06:03:00 -0300 Subject: [PATCH 4/4] Fix spelling. --- Sources/UInt128/UUID+UInt128.swift | 18 +++++++++--------- .../UInt128Tests/UInt128PerformanceTests.swift | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/UInt128/UUID+UInt128.swift b/Sources/UInt128/UUID+UInt128.swift index 2db3356..c6ac918 100644 --- a/Sources/UInt128/UUID+UInt128.swift +++ b/Sources/UInt128/UUID+UInt128.swift @@ -25,7 +25,7 @@ extension UUID { /// 128 bits, no truncation occurs. public init(_ longInt: UInt128) { let lowerBits = longInt.value.lowerBits - let upperBita = longInt.value.upperBits + let upperBits = longInt.value.upperBits let val: uuid_t = ( UInt8((lowerBits >> (0 * 8)) & 0xFF), UInt8((lowerBits >> (1 * 8)) & 0xFF), @@ -35,14 +35,14 @@ extension UUID { UInt8((lowerBits >> (5 * 8)) & 0xFF), UInt8((lowerBits >> (6 * 8)) & 0xFF), UInt8((lowerBits >> (7 * 8)) & 0xFF), - UInt8((upperBita >> (0 * 8)) & 0xFF), - UInt8((upperBita >> (1 * 8)) & 0xFF), - UInt8((upperBita >> (2 * 8)) & 0xFF), - UInt8((upperBita >> (3 * 8)) & 0xFF), - UInt8((upperBita >> (4 * 8)) & 0xFF), - UInt8((upperBita >> (5 * 8)) & 0xFF), - UInt8((upperBita >> (6 * 8)) & 0xFF), - UInt8((upperBita >> (7 * 8)) & 0xFF) + UInt8((upperBits >> (0 * 8)) & 0xFF), + UInt8((upperBits >> (1 * 8)) & 0xFF), + UInt8((upperBits >> (2 * 8)) & 0xFF), + UInt8((upperBits >> (3 * 8)) & 0xFF), + UInt8((upperBits >> (4 * 8)) & 0xFF), + UInt8((upperBits >> (5 * 8)) & 0xFF), + UInt8((upperBits >> (6 * 8)) & 0xFF), + UInt8((upperBits >> (7 * 8)) & 0xFF) ) self = .init(uuid: val) } diff --git a/Tests/UInt128Tests/UInt128PerformanceTests.swift b/Tests/UInt128Tests/UInt128PerformanceTests.swift index bf38c56..1ef71b4 100644 --- a/Tests/UInt128Tests/UInt128PerformanceTests.swift +++ b/Tests/UInt128Tests/UInt128PerformanceTests.swift @@ -45,7 +45,7 @@ final class CustomStringConvertiblePerformanceTests: XCTestCase { final class UUIDConvertibalePerformanceTests: XCTestCase { - func testUUIDPlus() { + func testUUIDConversion() { let uuid = UUID(uuidString: "1F349019-F3F5-489F-85F5-9CD214D6BD69")! let options = XCTMeasureOptions() options.iterationCount = 1000