Skip to content

Commit 23da1a4

Browse files
authored
Merge pull request #619 from lorentey/track-array-proposal
Track array proposal
2 parents 324c48a + bf8441d commit 23da1a4

7 files changed

Lines changed: 77 additions & 9 deletions

File tree

Sources/BasicContainers/RigidArray/RigidArray+Container.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ extension RigidArray where Element: ~Copyable {
303303
/// This optimization may be removed in future versions; do not rely on it.
304304
///
305305
/// - Parameter index: A valid index of the array. On return, `index` is
306-
/// set to `limit` if
306+
/// set to the resulting position.
307307
/// - Parameter n: The distance to offset `index`.
308308
/// On return, `n` is set to zero if the operation succeeded without
309309
/// hitting the limit; otherwise, `n` reflects the number of steps that

Sources/BasicContainers/RigidArray/RigidArray+Descriptions.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,35 @@
1313

1414
#if compiler(>=6.2)
1515

16+
// FIXME: Add this when/if SE-0499 gets implemented.
17+
//#if compiler(>=6.x)
18+
//@available(SwiftStdlib 5.0, *)
19+
//extension RigidArray: CustomStringConvertible where Element: ~Copyable {
20+
//}
21+
//#endif
22+
1623
@available(SwiftStdlib 5.0, *)
17-
extension RigidArray /*: CustomStringConvertible */ where Element: ~Copyable {
24+
extension RigidArray where Element: ~Copyable {
1825
public var description: String {
1926
/// FIXME: Print the item descriptions when available.
2027
"<\(count) items>"
2128
}
2229
}
2330

31+
// FIXME: Add this when/if SE-0499 gets implemented.
32+
//#if compiler(>=6.5)
33+
//@available(SwiftStdlib 5.0, *)
34+
//extension RigidArray: CustomDebugStringConvertible where Element: ~Copyable {
35+
//}
36+
//#endif
37+
2438
@available(SwiftStdlib 5.0, *)
25-
extension RigidArray /*: CustomDebugStringConvertible */ where Element: ~Copyable {
39+
extension RigidArray where Element: ~Copyable {
2640
public var debugDescription: String {
2741
/// FIXME: Print the item descriptions when available.
2842
"<\(count) items>"
2943
}
3044
}
3145

46+
3247
#endif

Sources/BasicContainers/RigidArray/RigidArray+Equatable.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@ import InternalCollectionsUtilities
1818
#endif
1919

2020
@available(SwiftStdlib 5.0, *)
21-
extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
21+
extension RigidArray where Element: ~Copyable {
2222
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
2323
self._storage._isIdentical(to: other._storage)
2424
&& self._count == other._count
2525
}
2626
}
2727

28-
28+
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
29+
@available(SwiftStdlib 5.0, *)
30+
extension RigidArray: Equatable where Element: Equatable & ~Copyable {
31+
@inlinable
32+
public static func ==(
33+
left: borrowing Self,
34+
right: borrowing Self
35+
) -> Bool {
36+
left.span._elementsEqual(to: right.span)
37+
}
38+
}
39+
#else
2940
@available(SwiftStdlib 5.0, *)
3041
extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
3142
@inlinable
@@ -36,5 +47,6 @@ extension RigidArray /*: Equatable */ where Element: Equatable /* & ~Copyable */
3647
left.span._elementsEqual(to: right.span)
3748
}
3849
}
50+
#endif
3951

4052
#endif

Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ extension UniqueArray where Element: ~Copyable {
264264
/// This optimization may be removed in future versions; do not rely on it.
265265
///
266266
/// - Parameter index: A valid index of the array. On return, `index` is
267-
/// set to `limit` if
267+
/// set to the resulting position.
268268
/// - Parameter n: The distance to offset `index`.
269269
/// On return, `n` is set to zero if the operation succeeded without
270270
/// hitting the limit; otherwise, `n` reflects the number of steps that

Sources/BasicContainers/UniqueArray/UniqueArray+Equatable.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,26 @@ import InternalCollectionsUtilities
1818
#endif
1919

2020
@available(SwiftStdlib 5.0, *)
21-
extension UniqueArray /*: Equatable */ where Element: Equatable /* & ~Copyable */ {
21+
extension UniqueArray where Element: ~Copyable {
22+
public func isTriviallyIdentical(to other: borrowing Self) -> Bool {
23+
self._storage.isTriviallyIdentical(to: other._storage)
24+
}
25+
}
26+
27+
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
28+
@available(SwiftStdlib 5.0, *)
29+
extension UniqueArray: Equatable where Element: Equatable & ~Copyable {
30+
@inlinable
31+
public static func ==(
32+
left: borrowing Self,
33+
right: borrowing Self
34+
) -> Bool {
35+
left.span._elementsEqual(to: right.span)
36+
}
37+
}
38+
#else
39+
@available(SwiftStdlib 5.0, *)
40+
extension UniqueArray where Element: Equatable {
2241
@inlinable
2342
public static func ==(
2443
left: borrowing Self,
@@ -27,5 +46,6 @@ extension UniqueArray /*: Equatable */ where Element: Equatable /* & ~Copyable *
2746
left.span._elementsEqual(to: right.span)
2847
}
2948
}
49+
#endif
3050

3151
#endif

Sources/BasicContainers/UniqueArray/UniqueArray+Insertions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ extension UniqueArray where Element: ~Copyable {
281281

282282
@available(SwiftStdlib 5.0, *)
283283
extension UniqueArray {
284-
/// Copyies the elements of a fully initialized buffer pointer into this
284+
/// Copies the elements of a fully initialized buffer pointer into this
285285
/// array at the specified position.
286286
///
287287
/// The new elements are inserted before the element currently at the
@@ -311,7 +311,7 @@ extension UniqueArray {
311311
unsafe _storage.insert(copying: newElements, at: index)
312312
}
313313

314-
/// Copyies the elements of a fully initialized buffer pointer into this
314+
/// Copies the elements of a fully initialized buffer pointer into this
315315
/// array at the specified position.
316316
///
317317
/// The new elements are inserted before the element currently at the

Sources/InternalCollectionsUtilities/Span+Extras.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ extension Span where Element: ~Copyable {
3838
}
3939
}
4040

41+
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
42+
@available(SwiftStdlib 5.0, *)
43+
extension Span where Element: Equatable & ~Copyable {
44+
@_alwaysEmitIntoClient
45+
package func _elementsEqual(to other: borrowing Self) -> Bool {
46+
return self.withUnsafeBufferPointer { a in
47+
other.withUnsafeBufferPointer { b in
48+
guard a.count == b.count else { return false }
49+
guard a.baseAddress != b.baseAddress else { return true }
50+
var i = 0
51+
while i < self.count {
52+
guard a[i] == b[i] else { return false }
53+
i &+= 1
54+
}
55+
return true
56+
}
57+
}
58+
}
59+
}
60+
#else
4161
@available(SwiftStdlib 5.0, *)
4262
extension Span where Element: Equatable /* & ~Copyable */ {
4363
@_alwaysEmitIntoClient
@@ -56,6 +76,7 @@ extension Span where Element: Equatable /* & ~Copyable */ {
5676
}
5777
}
5878
}
79+
#endif
5980

6081
@available(SwiftStdlib 5.0, *)
6182
extension Span where Element: Hashable /* & ~Copyable */ {

0 commit comments

Comments
 (0)