From b6050e36435a9cd7bca7136c63ba03aeb11176c1 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Sat, 16 Aug 2025 21:39:10 -0700 Subject: [PATCH] Add _isIdentical, _extracting(first:)/_extracting(last:) as UnsafeBufferPointer extensions --- .../CMakeLists.txt | 2 + .../UnsafeBufferPointer+Extras.swift.gyb | 60 ++++++++- ...nsafeMutableBufferPointer+Extras.swift.gyb | 59 ++++++++- ...feMutableRawBufferPointer+Extras.swift.gyb | 30 +++++ .../UnsafeRawBufferPointer+Extras.swift.gyb | 29 +++++ .../UnsafeBufferPointer+Extras.swift | 117 +++++++++++++++++- .../UnsafeMutableBufferPointer+Extras.swift | 116 ++++++++++++++++- ...UnsafeMutableRawBufferPointer+Extras.swift | 45 +++++++ .../UnsafeRawBufferPointer+Extras.swift | 43 +++++++ Xcode/Collections.xcodeproj/project.pbxproj | 14 ++- 10 files changed, 510 insertions(+), 5 deletions(-) create mode 100644 Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift.gyb create mode 100644 Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift.gyb create mode 100644 Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift create mode 100644 Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift diff --git a/Sources/InternalCollectionsUtilities/CMakeLists.txt b/Sources/InternalCollectionsUtilities/CMakeLists.txt index 61f942b7..b61f764d 100644 --- a/Sources/InternalCollectionsUtilities/CMakeLists.txt +++ b/Sources/InternalCollectionsUtilities/CMakeLists.txt @@ -27,6 +27,8 @@ target_sources(${module_name} PRIVATE "autogenerated/RandomAccessCollection+Offsets.swift" "autogenerated/UnsafeBufferPointer+Extras.swift" "autogenerated/UnsafeMutableBufferPointer+Extras.swift" + "autogenerated/UnsafeRawBufferPointer+Extras.swift" + "autogenerated/UnsafeMutableRawBufferPointer+Extras.swift" "IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift" "IntegerTricks/autogenerated/Integer rank.swift" "IntegerTricks/autogenerated/UInt+first and last set bit.swift" diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb index 603e3047..ff993060 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2025 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 @@ -24,5 +24,63 @@ extension UnsafeBufferPointer { return baseAddress.unsafelyUnwrapped + index } } + +extension UnsafeBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two `UnsafeBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + ${modifier} func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} + +extension UnsafeBufferPointer where Element: ~Copyable { + /// Returns a buffer pointer containing the initial elements of this buffer, + /// up to the specified maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// then the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } + + /// Returns a buffer pointer containing the final elements of this buffer, + /// up to the given maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// span from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let newCount = Swift.min(maxLength, count) + return extracting(Range(uncheckedBounds: (count - newCount, count))) + } +} % end ${visibility_boilerplate("end")} + diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb index 4d7cdde7..adc1b50c 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2025 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 @@ -16,6 +16,63 @@ ${autogenerated_warning()} % for modifier in visibility_levels: ${visibility_boilerplate(modifier)} +extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + ${modifier} func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} + +extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a buffer pointer containing the initial elements of this buffer, + /// up to the specified maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// then the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } + + /// Returns a buffer pointer containing the final elements of this buffer, + /// up to the given maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let newCount = Swift.min(maxLength, count) + return extracting(Range(uncheckedBounds: (count - newCount, count))) + } +} extension UnsafeMutableBufferPointer { @inlinable ${modifier} func initialize(fromContentsOf source: Self) -> Index { diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift.gyb new file mode 100644 index 00000000..8b649fbb --- /dev/null +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableRawBufferPointer+Extras.swift.gyb @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +%{ + from gyb_utils import * +}% +${autogenerated_warning()} + +% for modifier in visibility_levels: +${visibility_boilerplate(modifier)} +extension UnsafeMutableRawBufferPointer { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableRawBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + ${modifier} func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} +% end +${visibility_boilerplate("end")} + diff --git a/Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift.gyb new file mode 100644 index 00000000..dd3157f6 --- /dev/null +++ b/Sources/InternalCollectionsUtilities/UnsafeRawBufferPointer+Extras.swift.gyb @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + +%{ + from gyb_utils import * +}% +${autogenerated_warning()} + +% for modifier in visibility_levels: +${visibility_boilerplate(modifier)} +extension UnsafeRawBufferPointer { + /// Returns a Boolean value indicating whether two `UnsafeRawBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + ${modifier} func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} +% end +${visibility_boilerplate("end")} + diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift index 749f17bc..014ddf27 100644 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2021 - 2025 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 @@ -30,6 +30,63 @@ extension UnsafeBufferPointer { return baseAddress.unsafelyUnwrapped + index } } + +extension UnsafeBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two `UnsafeBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + internal func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} + +extension UnsafeBufferPointer where Element: ~Copyable { + /// Returns a buffer pointer containing the initial elements of this buffer, + /// up to the specified maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// then the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } + + /// Returns a buffer pointer containing the final elements of this buffer, + /// up to the given maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// span from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let newCount = Swift.min(maxLength, count) + return extracting(Range(uncheckedBounds: (count - newCount, count))) + } +} #else // !COLLECTIONS_SINGLE_MODULE extension UnsafeBufferPointer { @inlinable @@ -39,4 +96,62 @@ extension UnsafeBufferPointer { return baseAddress.unsafelyUnwrapped + index } } + +extension UnsafeBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two `UnsafeBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + public func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} + +extension UnsafeBufferPointer where Element: ~Copyable { + /// Returns a buffer pointer containing the initial elements of this buffer, + /// up to the specified maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// then the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } + + /// Returns a buffer pointer containing the final elements of this buffer, + /// up to the given maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// span from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let newCount = Swift.min(maxLength, count) + return extracting(Range(uncheckedBounds: (count - newCount, count))) + } +} #endif // COLLECTIONS_SINGLE_MODULE + diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift index be578b23..dd833474 100644 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift Collections open source project // -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors +// Copyright (c) 2022 - 2025 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 @@ -22,6 +22,63 @@ // but in regular builds we want them to be public. Unfortunately // the current best way to do this is to duplicate all definitions. #if COLLECTIONS_SINGLE_MODULE +extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + internal func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} + +extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a buffer pointer containing the initial elements of this buffer, + /// up to the specified maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// then the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } + + /// Returns a buffer pointer containing the final elements of this buffer, + /// up to the given maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let newCount = Swift.min(maxLength, count) + return extracting(Range(uncheckedBounds: (count - newCount, count))) + } +} extension UnsafeMutableBufferPointer { @inlinable internal func initialize(fromContentsOf source: Self) -> Index { @@ -149,6 +206,63 @@ extension Slice { } } #else // !COLLECTIONS_SINGLE_MODULE +extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + public func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} + +extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a buffer pointer containing the initial elements of this buffer, + /// up to the specified maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// then the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(first maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a prefix of negative length") + let newCount = Swift.min(maxLength, count) + return Self(start: baseAddress, count: newCount) + } + + /// Returns a buffer pointer containing the final elements of this buffer, + /// up to the given maximum length. + /// + /// If the maximum length exceeds the length of this buffer pointer, + /// the result contains all the elements. + /// + /// The returned buffer's first item is always at offset 0; unlike buffer + /// slices, extracted buffers do not share their indices with the + /// buffer from which they are extracted. + /// + /// - Parameter maxLength: The maximum number of elements to return. + /// `maxLength` must be greater than or equal to zero. + /// - Returns: A buffer pointer with at most `maxLength` elements. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @inline(__always) + public func _extracting(last maxLength: Int) -> Self { + precondition(maxLength >= 0, "Can't have a suffix of negative length") + let newCount = Swift.min(maxLength, count) + return extracting(Range(uncheckedBounds: (count - newCount, count))) + } +} extension UnsafeMutableBufferPointer { @inlinable public func initialize(fromContentsOf source: Self) -> Index { diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift new file mode 100644 index 00000000..b97bfe3b --- /dev/null +++ b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableRawBufferPointer+Extras.swift @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + + +// ############################################################################# +// # # +// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # +// # # +// ############################################################################# + + + +// In single module mode, we need these declarations to be internal, +// but in regular builds we want them to be public. Unfortunately +// the current best way to do this is to duplicate all definitions. +#if COLLECTIONS_SINGLE_MODULE +extension UnsafeMutableRawBufferPointer { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableRawBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + internal func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} +#else // !COLLECTIONS_SINGLE_MODULE +extension UnsafeMutableRawBufferPointer { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableRawBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + public func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} +#endif // COLLECTIONS_SINGLE_MODULE + diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift new file mode 100644 index 00000000..7caa59d0 --- /dev/null +++ b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeRawBufferPointer+Extras.swift @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2025 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 +// +//===----------------------------------------------------------------------===// + + +// ############################################################################# +// # # +// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. # +// # # +// ############################################################################# + + + +// In single module mode, we need these declarations to be internal, +// but in regular builds we want them to be public. Unfortunately +// the current best way to do this is to duplicate all definitions. +#if COLLECTIONS_SINGLE_MODULE +extension UnsafeRawBufferPointer { + /// Returns a Boolean value indicating whether two `UnsafeRawBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + internal func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} +#else // !COLLECTIONS_SINGLE_MODULE +extension UnsafeRawBufferPointer { + /// Returns a Boolean value indicating whether two `UnsafeRawBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + public func _isIdentical(to other: Self) -> Bool { + (self.baseAddress == other.baseAddress) && (self.count == other.count) + } +} +#endif // COLLECTIONS_SINGLE_MODULE + diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 43bceca8..a1777e22 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -11,6 +11,8 @@ 7D48BCDC2E51554900D7F6F7 /* ClassBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCDB2E51554900D7F6F7 /* ClassBox.swift */; }; 7D48BCE02E51558700D7F6F7 /* LifetimeTrackedStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCDE2E51558700D7F6F7 /* LifetimeTrackedStruct.swift */; }; 7D48BCEE2E5158A100D7F6F7 /* BoxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCE62E5158A100D7F6F7 /* BoxTests.swift */; }; + 7D48BCFE2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCFD2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift */; }; + 7D48BCFF2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCFC2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift */; }; 7D48BD002E5182CE00D7F6F7 /* LifetimeOverride.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D48BCFA2E5182CE00D7F6F7 /* LifetimeOverride.swift */; }; 7D9B859729E4F74400B291CD /* BitArray+Shifts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859129E4F74400B291CD /* BitArray+Shifts.swift */; }; 7D9B859829E4F74400B291CD /* BitArray+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859229E4F74400B291CD /* BitArray+Descriptions.swift */; }; @@ -436,7 +438,11 @@ 7D48BCE62E5158A100D7F6F7 /* BoxTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxTests.swift; sourceTree = ""; }; 7D48BCF52E51651900D7F6F7 /* Package@swift-6.0.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Package@swift-6.0.swift"; path = "../Package@swift-6.0.swift"; sourceTree = SOURCE_ROOT; }; 7D48BCF62E5172CF00D7F6F7 /* LifetimeOverride.swift.gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = LifetimeOverride.swift.gyb; sourceTree = ""; }; + 7D48BCF82E5172CF00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift.gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = "UnsafeMutableRawBufferPointer+Extras.swift.gyb"; sourceTree = ""; }; + 7D48BCF92E5172CF00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift.gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = "UnsafeRawBufferPointer+Extras.swift.gyb"; sourceTree = ""; }; 7D48BCFA2E5182CE00D7F6F7 /* LifetimeOverride.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifetimeOverride.swift; sourceTree = ""; }; + 7D48BCFC2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableRawBufferPointer+Extras.swift"; sourceTree = ""; }; + 7D48BCFD2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeRawBufferPointer+Extras.swift"; sourceTree = ""; }; 7D5A64D229CCE8CC00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D329CCEE9A00CB2595 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 7D5A64D429CCEF1500CB2595 /* generate-sources.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "generate-sources.sh"; sourceTree = ""; }; @@ -1264,6 +1270,7 @@ 7DEBDAD329CBEE5300ADC226 /* autogenerated */, 7DEBDAE229CBEE5300ADC226 /* IntegerTricks */, 7DEBDADA29CBEE5300ADC226 /* UnsafeBitSet */, + 7DE91F2E29CA70F3004483EB /* CMakeLists.txt */, 7DE91F3029CA70F3004483EB /* _SortedCollection.swift */, 7DE91F3829CA70F3004483EB /* _UniqueCollection.swift */, 7DEBDAED29CBEE5300ADC226 /* Debugging.swift.gyb */, @@ -1272,7 +1279,8 @@ 7DEBDAD229CBEE5200ADC226 /* RandomAccessCollection+Offsets.swift.gyb */, 7DEBDAD929CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift.gyb */, 7DEBDAEC29CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift.gyb */, - 7DE91F2E29CA70F3004483EB /* CMakeLists.txt */, + 7D48BCF82E5172CF00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift.gyb */, + 7D48BCF92E5172CF00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift.gyb */, ); path = InternalCollectionsUtilities; sourceTree = ""; @@ -1665,6 +1673,8 @@ 7DEBDAD629CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift */, 7DEBDAD529CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift */, 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */, + 7D48BCFC2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift */, + 7D48BCFD2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift */, ); path = autogenerated; sourceTree = ""; @@ -2113,6 +2123,8 @@ 7DE9213D29CA70F4004483EB /* TreeSet+SetAlgebra isSubset.swift in Sources */, 7DE9203029CA70F3004483EB /* OrderedSet+SubSequence.swift in Sources */, 7DE9215529CA70F4004483EB /* _RawHashNode+UnsafeHandle.swift in Sources */, + 7D48BCFE2E5182CE00D7F6F7 /* UnsafeRawBufferPointer+Extras.swift in Sources */, + 7D48BCFF2E5182CE00D7F6F7 /* UnsafeMutableRawBufferPointer+Extras.swift in Sources */, 7D48BD002E5182CE00D7F6F7 /* LifetimeOverride.swift in Sources */, 7DE9209429CA70F4004483EB /* Rope+_UnmanagedLeaf.swift in Sources */, 7DE9208429CA70F4004483EB /* BigString+Equatable.swift in Sources */,