Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 14 additions & 2 deletions Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,5 +47,6 @@ extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */
left.span._elementsEqual(to: right.span)
}
}
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,5 +46,6 @@ extension UniqueArray /*: Equatable */ where Element: Equatable /* & ~Copyable *
left.span._elementsEqual(to: right.span)
}
}
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions Sources/InternalCollectionsUtilities/Span+Extras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,6 +76,7 @@ extension Span where Element: Equatable /* & ~Copyable */ {
}
}
}
#endif

@available(SwiftStdlib 5.0, *)
extension Span where Element: Hashable /* & ~Copyable */ {
Expand Down
Loading