File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
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 @@ -1067,9 +1067,16 @@ extension ArraySlice: RangeReplaceableCollection {
1067
1067
if !keepCapacity {
1068
1068
_buffer = _Buffer ( )
1069
1069
}
1070
- else {
1070
+ else if _buffer . isMutableAndUniquelyReferenced ( ) {
1071
1071
self . replaceSubrange ( indices, with: EmptyCollection ( ) )
1072
1072
}
1073
+ else {
1074
+ let buffer = _ContiguousArrayBuffer < Element > (
1075
+ _uninitializedCount: 0 ,
1076
+ minimumCapacity: capacity
1077
+ )
1078
+ _buffer = _Buffer ( _buffer: buffer, shiftedToStartIndex: startIndex)
1079
+ }
1073
1080
}
1074
1081
1075
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