mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04: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
@@ -262,20 +262,21 @@ extension RigidDeque where Element: ~Copyable {
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
public subscript(position: Int) -> Element {
|
||||
// FIXME: Replace with borrow/mutate accessors
|
||||
@inline(__always)
|
||||
@_transparent
|
||||
unsafeAddress {
|
||||
@_unsafeSelfDependentResult
|
||||
borrow {
|
||||
_checkItemIndex(position)
|
||||
let slot = _handle.slot(forOffset: position)
|
||||
return _handle.ptr(at: slot)
|
||||
return _handle.ptr(at: slot).pointee
|
||||
}
|
||||
@inline(__always)
|
||||
@_transparent
|
||||
unsafeMutableAddress {
|
||||
@_unsafeSelfDependentResult
|
||||
mutate {
|
||||
_checkItemIndex(position)
|
||||
let slot = _handle.slot(forOffset: position)
|
||||
return _handle.mutablePtr(at: slot)
|
||||
return &_handle.mutablePtr(at: slot).pointee
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,17 +198,14 @@ extension UniqueDeque where Element: ~Copyable {
|
||||
public subscript(position: Int) -> Element {
|
||||
@inline(__always)
|
||||
@_transparent
|
||||
unsafeAddress {
|
||||
precondition(position >= 0 && position < count, "Index out of bounds")
|
||||
let slot = _storage._handle.slot(forOffset: position)
|
||||
return _storage._handle.ptr(at: slot)
|
||||
borrow {
|
||||
_storage[position]
|
||||
}
|
||||
@inline(__always)
|
||||
@_transparent
|
||||
unsafeMutableAddress {
|
||||
precondition(position >= 0 && position < count, "Index out of bounds")
|
||||
let slot = _storage._handle.slot(forOffset: position)
|
||||
return _storage._handle.mutablePtr(at: slot)
|
||||
@_unsafeSelfDependentResult // FIXME: Why is this necessary?
|
||||
mutate {
|
||||
&_storage[position]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user