diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index 1dfa411e2..9cc46ed17 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -303,7 +303,7 @@ extension RigidArray where Element: ~Copyable { /// This optimization may be removed in future versions; do not rely on it. /// /// - Parameter index: A valid index of the array. On return, `index` is - /// set to `limit` if + /// set to the resulting position. /// - Parameter n: The distance to offset `index`. /// On return, `n` is set to zero if the operation succeeded without /// hitting the limit; otherwise, `n` reflects the number of steps that diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift index 73a829132..5043d4cd2 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift @@ -13,20 +13,35 @@ #if compiler(>=6.2) +// FIXME: Add this when/if SE-0499 gets implemented. +//#if compiler(>=6.x) +//@available(SwiftStdlib 5.0, *) +//extension RigidArray: CustomStringConvertible where Element: ~Copyable { +//} +//#endif + @available(SwiftStdlib 5.0, *) -extension RigidArray /*: CustomStringConvertible */ where Element: ~Copyable { +extension RigidArray where Element: ~Copyable { public var description: String { /// FIXME: Print the item descriptions when available. "<\(count) items>" } } +// FIXME: Add this when/if SE-0499 gets implemented. +//#if compiler(>=6.5) +//@available(SwiftStdlib 5.0, *) +//extension RigidArray: CustomDebugStringConvertible where Element: ~Copyable { +//} +//#endif + @available(SwiftStdlib 5.0, *) -extension RigidArray /*: CustomDebugStringConvertible */ where Element: ~Copyable { +extension RigidArray where Element: ~Copyable { public var debugDescription: String { /// FIXME: Print the item descriptions when available. "<\(count) items>" } } + #endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift b/Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift index 2a2a37ede..b0cc93164 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift @@ -18,14 +18,25 @@ import InternalCollectionsUtilities #endif @available(SwiftStdlib 5.0, *) -extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ { +extension RigidArray where Element: ~Copyable { public func isTriviallyIdentical(to other: borrowing Self) -> Bool { self._storage._isIdentical(to: other._storage) && self._count == other._count } } - +#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension RigidArray: Equatable where Element: Equatable & ~Copyable { + @inlinable + public static func ==( + left: borrowing Self, + right: borrowing Self + ) -> Bool { + left.span._elementsEqual(to: right.span) + } +} +#else @available(SwiftStdlib 5.0, *) extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ { @inlinable @@ -36,5 +47,6 @@ extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ left.span._elementsEqual(to: right.span) } } +#endif #endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift index 2917ee85a..defd02cd6 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift @@ -264,7 +264,7 @@ extension UniqueArray where Element: ~Copyable { /// This optimization may be removed in future versions; do not rely on it. /// /// - Parameter index: A valid index of the array. On return, `index` is - /// set to `limit` if + /// set to the resulting position. /// - Parameter n: The distance to offset `index`. /// On return, `n` is set to zero if the operation succeeded without /// hitting the limit; otherwise, `n` reflects the number of steps that diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift index 8b10c1e1b..722c14187 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift @@ -18,7 +18,26 @@ import InternalCollectionsUtilities #endif @available(SwiftStdlib 5.0, *) -extension UniqueArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ { +extension UniqueArray where Element: ~Copyable { + public func isTriviallyIdentical(to other: borrowing Self) -> Bool { + self._storage.isTriviallyIdentical(to: other._storage) + } +} + +#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension UniqueArray: Equatable where Element: Equatable & ~Copyable { + @inlinable + public static func ==( + left: borrowing Self, + right: borrowing Self + ) -> Bool { + left.span._elementsEqual(to: right.span) + } +} +#else +@available(SwiftStdlib 5.0, *) +extension UniqueArray where Element: Equatable { @inlinable public static func ==( left: borrowing Self, @@ -27,5 +46,6 @@ extension UniqueArray /*: Equatable */ where Element: Equatable /* & ~Copyable * left.span._elementsEqual(to: right.span) } } +#endif #endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift index a86ed57b0..7e8c2f7d8 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift @@ -281,7 +281,7 @@ extension UniqueArray where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension UniqueArray { - /// Copyies the elements of a fully initialized buffer pointer into this + /// Copies the elements of a fully initialized buffer pointer into this /// array at the specified position. /// /// The new elements are inserted before the element currently at the @@ -311,7 +311,7 @@ extension UniqueArray { unsafe _storage.insert(copying: newElements, at: index) } - /// Copyies the elements of a fully initialized buffer pointer into this + /// Copies the elements of a fully initialized buffer pointer into this /// array at the specified position. /// /// The new elements are inserted before the element currently at the diff --git a/Sources/InternalCollectionsUtilities/Span+Extras.swift b/Sources/InternalCollectionsUtilities/Span+Extras.swift index 3abfd8b6d..e23582ef4 100644 --- a/Sources/InternalCollectionsUtilities/Span+Extras.swift +++ b/Sources/InternalCollectionsUtilities/Span+Extras.swift @@ -38,6 +38,26 @@ extension Span where Element: ~Copyable { } } +#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW +@available(SwiftStdlib 5.0, *) +extension Span where Element: Equatable & ~Copyable { + @_alwaysEmitIntoClient + package func _elementsEqual(to other: borrowing Self) -> Bool { + return self.withUnsafeBufferPointer { a in + other.withUnsafeBufferPointer { b in + guard a.count == b.count else { return false } + guard a.baseAddress != b.baseAddress else { return true } + var i = 0 + while i < self.count { + guard a[i] == b[i] else { return false } + i &+= 1 + } + return true + } + } + } +} +#else @available(SwiftStdlib 5.0, *) extension Span where Element: Equatable /* & ~Copyable */ { @_alwaysEmitIntoClient @@ -56,6 +76,7 @@ extension Span where Element: Equatable /* & ~Copyable */ { } } } +#endif @available(SwiftStdlib 5.0, *) extension Span where Element: Hashable /* & ~Copyable */ {