Skip to content

Commit dc1b73f

Browse files
authored
Merge pull request #63458 from apple/egorzhdan/cxx-convertible-mutable
[cxx-interop] Avoid extra copy in `CxxConvertibleToCollection`
2 parents be51881 + ad20822 commit dc1b73f

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

stdlib/public/Cxx/CxxConvertibleToCollection.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@ public protocol CxxConvertibleToCollection<Element> {
1717
where RawIterator.Pointee == Element
1818

1919
/// Do not implement this function manually in Swift.
20-
mutating func __beginUnsafe() -> RawIterator
20+
func __beginUnsafe() -> RawIterator
2121

2222
/// Do not implement this function manually in Swift.
23-
mutating func __endUnsafe() -> RawIterator
23+
func __endUnsafe() -> RawIterator
2424
}
2525

2626
extension CxxConvertibleToCollection {
2727
@inlinable
2828
internal func forEach(_ body: (RawIterator.Pointee) -> Void) {
29-
var mutableSelf = self
30-
var rawIterator = mutableSelf.__beginUnsafe()
31-
let endIterator = mutableSelf.__endUnsafe()
29+
var rawIterator = __beginUnsafe()
30+
let endIterator = __endUnsafe()
3231
while rawIterator != endIterator {
3332
body(rawIterator.pointee)
3433
rawIterator = rawIterator.successor()
3534
}
36-
withExtendedLifetime(mutableSelf) {}
3735
}
3836
}
3937

0 commit comments

Comments
 (0)