Skip to content

Commit 5d0c6e6

Browse files
authored
Merge pull request #60973 from lorentey/fix-modify-implementations
[stdlib] _modify: Ensure cleanup is always executed
2 parents 3211b93 + 7cbadf2 commit 5d0c6e6

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

stdlib/public/core/Array.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ extension Array: RandomAccessCollection, MutableCollection {
751751
_makeMutableAndUnique() // makes the array native, too
752752
_checkSubscript_mutating(index)
753753
let address = _buffer.mutableFirstElementAddress + index
754+
defer { _endMutation() }
754755
yield &address.pointee
755-
_endMutation();
756756
}
757757
}
758758

stdlib/public/core/ArraySlice.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ extension ArraySlice: RandomAccessCollection, MutableCollection {
546546
_makeMutableAndUnique() // makes the array native, too
547547
_checkSubscript_native(index)
548548
let address = _buffer.subscriptBaseAddress + index
549+
defer { _endMutation() }
549550
yield &address.pointee
550-
_endMutation();
551551
}
552552
}
553553

stdlib/public/core/ContiguousArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ extension ContiguousArray: RandomAccessCollection, MutableCollection {
409409
_makeMutableAndUnique()
410410
_checkSubscript_mutating(index)
411411
let address = _buffer.mutableFirstElementAddress + index
412+
defer { _endMutation() }
412413
yield &address.pointee
413-
_endMutation();
414414
}
415415
}
416416

0 commit comments

Comments
 (0)