Skip to content
Merged
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
9 changes: 8 additions & 1 deletion stdlib/public/core/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1378,9 +1378,16 @@ extension Array: RangeReplaceableCollection {
if !keepCapacity {
_buffer = _Buffer()
}
else {
else if _buffer.isMutableAndUniquelyReferenced() {
self.replaceSubrange(indices, with: EmptyCollection())
}
else {
let buffer = _ContiguousArrayBuffer<Element>(
_uninitializedCount: 0,
minimumCapacity: capacity
)
_buffer = _Buffer(_buffer: buffer, shiftedToStartIndex: startIndex)
}
}

//===--- algorithms -----------------------------------------------------===//
Expand Down
13 changes: 8 additions & 5 deletions stdlib/public/core/ArraySlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,7 @@ extension ArraySlice {
func _checkSubscript(
_ index: Int, wasNativeTypeChecked: Bool
) -> _DependenceToken {
#if _runtime(_ObjC)
_buffer._checkValidSubscript(index)
#else
_buffer._checkValidSubscript(index)
#endif
return _DependenceToken()
}

Expand Down Expand Up @@ -1071,9 +1067,16 @@ extension ArraySlice: RangeReplaceableCollection {
if !keepCapacity {
_buffer = _Buffer()
}
else {
else if _buffer.isMutableAndUniquelyReferenced() {
self.replaceSubrange(indices, with: EmptyCollection())
}
else {
let buffer = _ContiguousArrayBuffer<Element>(
_uninitializedCount: 0,
minimumCapacity: capacity
)
_buffer = _Buffer(_buffer: buffer, shiftedToStartIndex: startIndex)
}
}

//===--- algorithms -----------------------------------------------------===//
Expand Down
5 changes: 4 additions & 1 deletion stdlib/public/core/ContiguousArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,12 @@ extension ContiguousArray: RangeReplaceableCollection {
if !keepCapacity {
_buffer = _Buffer()
}
else {
else if _buffer.isMutableAndUniquelyReferenced() {
self.replaceSubrange(indices, with: EmptyCollection())
}
else {
_buffer = _Buffer(_uninitializedCount: 0, minimumCapacity: capacity)
}
}

//===--- algorithms -----------------------------------------------------===//
Expand Down