mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
Add subscript requirements to [Mutable]Container with borrow/mutate accessors
This commit is contained in:
11 files changed
+59
-41
No files matched your search
@@ -41,7 +41,7 @@ extension RigidArray: BidirectionalContainer where Element: ~Copyable {}
|
||||
extension RigidArray: RandomAccessContainer where Element: ~Copyable {}
|
||||
|
||||
#if compiler(>=6.4)
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension RigidArray: MutableContainer where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 6.4, *)
|
||||
@@ -153,12 +153,14 @@ extension RigidArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
public subscript(position: Int) -> Element {
|
||||
@inline(__always)
|
||||
unsafeAddress {
|
||||
_ptr(to: position)
|
||||
@_unsafeSelfDependentResult
|
||||
borrow {
|
||||
_ptr(to: position).pointee
|
||||
}
|
||||
@inline(__always)
|
||||
unsafeMutableAddress {
|
||||
_mutablePtr(to: position)
|
||||
@_unsafeSelfDependentResult
|
||||
mutate {
|
||||
&_mutablePtr(to: position).pointee
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +100,10 @@ extension RigidSet where Element: ~Copyable {
|
||||
|
||||
@inlinable
|
||||
public subscript(index: Index) -> Element {
|
||||
// FIXME: Use borrow accessor here
|
||||
unsafeAddress {
|
||||
@_unsafeSelfDependentResult
|
||||
borrow {
|
||||
_checkItemIndex(index)
|
||||
return .init(_memberPtr(at: index._bucket))
|
||||
return _memberPtr(at: index._bucket).pointee
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,12 +114,13 @@ extension UniqueArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
public subscript(position: Int) -> Element {
|
||||
@inline(__always)
|
||||
unsafeAddress {
|
||||
_storage._ptr(to: position)
|
||||
borrow {
|
||||
_storage[position]
|
||||
}
|
||||
@inline(__always)
|
||||
unsafeMutableAddress {
|
||||
_storage._mutablePtr(to: position)
|
||||
@_unsafeSelfDependentResult // FIXME: Why is this necessary?
|
||||
mutate {
|
||||
&_storage[position]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,8 @@ extension UniqueSet where Element: ~Copyable {
|
||||
|
||||
@inlinable
|
||||
public subscript(index: Index) -> Element {
|
||||
// FIXME: Use borrow accessor here
|
||||
unsafeAddress {
|
||||
_checkItemIndex(index)
|
||||
return .init(_storage._memberPtr(at: index._bucket))
|
||||
borrow {
|
||||
_storage[index]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user