Skip to content

Commit 87e9fb5

Browse files
committed
Use @_borrowed on a few declarations in the stdlib and overlays.
Most of the stdlib's properties don't need @_borrowed because they're @inlinable, but I did find one place in an overlay where it's probably sensible to make the operation use generalized accessors even if they're resilient.
1 parent 4758b2f commit 87e9fb5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

stdlib/public/SDK/CoreAudio/CoreAudio.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,17 @@ extension UnsafeMutableAudioBufferListPointer
151151
}
152152

153153
/// Access an indexed `AudioBuffer` (`mBuffers[i]`).
154+
@_borrowed
154155
public subscript(index: Index) -> Element {
155-
get {
156+
_read {
156157
precondition(index >= 0 && index < self.count,
157158
"subscript index out of range")
158-
return (_audioBuffersPointer + index).pointee
159+
yield ((_audioBuffersPointer + index).pointee)
159160
}
160-
nonmutating set(newValue) {
161+
nonmutating _modify {
161162
precondition(index >= 0 && index < self.count,
162163
"subscript index out of range")
163-
(_audioBuffersPointer + index).pointee = newValue
164+
yield (&(_audioBuffersPointer + index).pointee)
164165
}
165166
}
166167
}

stdlib/public/core/Collection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
411411
/// `endIndex` property.
412412
///
413413
/// - Complexity: O(1)
414+
@_borrowed
414415
subscript(position: Index) -> Element { get }
415416

416417
/// Accesses a contiguous subrange of the collection's elements.

stdlib/public/core/MutableCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ where SubSequence: MutableCollection
8585
/// `endIndex` property.
8686
///
8787
/// - Complexity: O(1)
88+
@_borrowed
8889
override subscript(position: Index) -> Element { get set }
8990

9091
/// Accesses a contiguous subrange of the collection's elements.

0 commit comments

Comments
 (0)