Skip to content
Closed
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
4 changes: 2 additions & 2 deletions stdlib/public/core/CollectionOfOne.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
/// valid position in a `CollectionOfOne` instance is `0`.
@inlinable // trivial-implementation
public subscript(position: Int) -> Element {
get {
_read {
_precondition(position == 0, "Index out of range")
return _element
yield _element
}
_modify {
_precondition(position == 0, "Index out of range")
Expand Down
12 changes: 6 additions & 6 deletions stdlib/public/core/Slice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ extension Slice: Collection {

@inlinable // generic-performance
public subscript(index: Index) -> Base.Element {
get {
_read {
_failEarlyRangeCheck(index, bounds: startIndex..<endIndex)
return _base[index]
yield _base[index]
}
}

Expand Down Expand Up @@ -235,13 +235,13 @@ extension Slice: BidirectionalCollection where Base: BidirectionalCollection {
extension Slice: MutableCollection where Base: MutableCollection {
@inlinable // generic-performance
public subscript(index: Index) -> Base.Element {
get {
_read {
_failEarlyRangeCheck(index, bounds: startIndex..<endIndex)
return _base[index]
yield _base[index]
}
set {
_modify {
_failEarlyRangeCheck(index, bounds: startIndex..<endIndex)
_base[index] = newValue
yield &_base[index]
// MutableSlice requires that the underlying collection's subscript
// setter does not invalidate indices, so our `startIndex` and `endIndex`
// continue to be valid.
Expand Down
26 changes: 21 additions & 5 deletions stdlib/public/core/Substring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ extension Substring: StringProtocol {
}

public subscript(i: Index) -> Character {
return _slice[i]
_read {
yield _slice[i]
}
}

public mutating func replaceSubrange<C>(
Expand Down Expand Up @@ -360,7 +362,11 @@ extension Substring.UTF8View : BidirectionalCollection {
public var endIndex: Index { return _slice.endIndex }

@inlinable
public subscript(index: Index) -> Element { return _slice[index] }
public subscript(index: Index) -> Element {
_read {
yield _slice[index]
}
}

@inlinable
public var indices: Indices { return _slice.indices }
Expand Down Expand Up @@ -486,7 +492,11 @@ extension Substring.UTF16View : BidirectionalCollection {
public var endIndex: Index { return _slice.endIndex }

@inlinable
public subscript(index: Index) -> Element { return _slice[index] }
public subscript(index: Index) -> Element {
_read {
yield _slice[index]
}
}

@inlinable
public var indices: Indices { return _slice.indices }
Expand Down Expand Up @@ -612,7 +622,11 @@ extension Substring.UnicodeScalarView : BidirectionalCollection {
public var endIndex: Index { return _slice.endIndex }

@inlinable
public subscript(index: Index) -> Element { return _slice[index] }
public subscript(index: Index) -> Element {
_read {
yield _slice[index]
}
}

@inlinable
public var indices: Indices { return _slice.indices }
Expand Down Expand Up @@ -801,7 +815,9 @@ extension Substring {
@inlinable
@available(swift, introduced: 4)
public subscript(r: Range<Index>) -> Substring {
return Substring(_slice[r])
_read {
yield Substring(_slice[r])
}
}
}

Expand Down