Skip to content

Commit 6bb0b8e

Browse files
committed
[cxx-interop] Optimize default impls of CxxRandomAccessCollection
1 parent bc16131 commit 6bb0b8e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/public/Cxx/CxxRandomAccessCollection.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,30 @@ public protocol CxxRandomAccessCollection: CxxSequence, RandomAccessCollection {
4040
}
4141

4242
extension CxxRandomAccessCollection {
43+
@inlinable
4344
public var startIndex: Int {
4445
return 0
4546
}
4647

48+
@inlinable
4749
public var endIndex: Int {
4850
return count
4951
}
5052

53+
@inlinable
5154
public var count: Int {
5255
return Int(__endUnsafe() - __beginUnsafe())
5356
}
5457

5558
/// A C++ implementation of the subscript might be more performant. This
5659
/// overload should only be used if the C++ type does not define `operator[]`.
60+
@inlinable
5761
public subscript(_ index: Int) -> Element {
58-
get {
62+
_read {
5963
// Not using CxxIterator here to avoid making a copy of the collection.
6064
var rawIterator = __beginUnsafe()
6165
rawIterator += RawIterator.Distance(index)
62-
return rawIterator.pointee as! Element
66+
yield rawIterator.pointee as! Element
6367
}
6468
}
6569
}

0 commit comments

Comments
 (0)