File tree Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Expand file tree Collapse file tree 3 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -1378,9 +1378,16 @@ extension Array: RangeReplaceableCollection {
1378
1378
if !keepCapacity {
1379
1379
_buffer = _Buffer ( )
1380
1380
}
1381
- else {
1381
+ else if _buffer . isMutableAndUniquelyReferenced ( ) {
1382
1382
self . replaceSubrange ( indices, with: EmptyCollection ( ) )
1383
1383
}
1384
+ else {
1385
+ let buffer = _ContiguousArrayBuffer < Element > (
1386
+ _uninitializedCount: 0 ,
1387
+ minimumCapacity: capacity
1388
+ )
1389
+ _buffer = _Buffer ( _buffer: buffer, shiftedToStartIndex: startIndex)
1390
+ }
1384
1391
}
1385
1392
1386
1393
//===--- algorithms -----------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -195,11 +195,7 @@ extension ArraySlice {
195
195
func _checkSubscript(
196
196
_ index: Int , wasNativeTypeChecked: Bool
197
197
) -> _DependenceToken {
198
- #if _runtime(_ObjC)
199
198
_buffer. _checkValidSubscript ( index)
200
- #else
201
- _buffer. _checkValidSubscript ( index)
202
- #endif
203
199
return _DependenceToken ( )
204
200
}
205
201
@@ -1071,9 +1067,16 @@ extension ArraySlice: RangeReplaceableCollection {
1071
1067
if !keepCapacity {
1072
1068
_buffer = _Buffer ( )
1073
1069
}
1074
- else {
1070
+ else if _buffer . isMutableAndUniquelyReferenced ( ) {
1075
1071
self . replaceSubrange ( indices, with: EmptyCollection ( ) )
1076
1072
}
1073
+ else {
1074
+ let buffer = _ContiguousArrayBuffer < Element > (
1075
+ _uninitializedCount: 0 ,
1076
+ minimumCapacity: capacity
1077
+ )
1078
+ _buffer = _Buffer ( _buffer: buffer, shiftedToStartIndex: startIndex)
1079
+ }
1077
1080
}
1078
1081
1079
1082
//===--- algorithms -----------------------------------------------------===//
Original file line number Diff line number Diff line change @@ -975,9 +975,12 @@ extension ContiguousArray: RangeReplaceableCollection {
975
975
if !keepCapacity {
976
976
_buffer = _Buffer ( )
977
977
}
978
- else {
978
+ else if _buffer . isMutableAndUniquelyReferenced ( ) {
979
979
self . replaceSubrange ( indices, with: EmptyCollection ( ) )
980
980
}
981
+ else {
982
+ _buffer = _Buffer ( _uninitializedCount: 0 , minimumCapacity: capacity)
983
+ }
981
984
}
982
985
983
986
//===--- algorithms -----------------------------------------------------===//
You can’t perform that action at this time.
0 commit comments