@@ -17,34 +17,32 @@ let arrayCount = 1024
17
17
18
18
// This test case exposes rdar://17440222 which caused rdar://17974483 (popFront
19
19
// being really slow).
20
+ protocol MyArrayBufferProtocol : MutableCollection , RandomAccessCollection {
21
+ associatedtype Element
20
22
21
- func _arrayReplace< B: _ArrayBufferProtocol , C: Collection
23
+ mutating func myReplace< C> (
24
+ _ subRange: Range < Int > ,
25
+ with newValues: C
26
+ ) where C : Collection , C. Iterator. Element == Element
27
+ }
28
+
29
+ extension Array : MyArrayBufferProtocol {
30
+ mutating func myReplace< C> (
31
+ _ subRange: Range < Int > ,
32
+ with newValues: C
33
+ ) where C : Collection , C. Iterator. Element == Element {
34
+ replaceSubrange ( subRange, with: newValues)
35
+ }
36
+ }
37
+
38
+ func myArrayReplace< B: MyArrayBufferProtocol , C: Collection
22
39
where C. Iterator. Element == B . Element , B. Index == Int
23
40
> (
24
41
_ target: inout B , _ subRange: Range < Int > , _ newValues: C
25
42
) {
26
- _precondition (
27
- subRange. lowerBound >= 0 ,
28
- " Array replace: subRange start is negative " )
29
-
30
- _precondition (
31
- subRange. upperBound <= target. endIndex,
32
- " Array replace: subRange extends past the end " )
33
-
34
- let oldCount = target. count
35
- let eraseCount = subRange. count
36
- let insertCount = numericCast ( newValues. count) as Int
37
- let growth = insertCount - eraseCount
38
-
39
- if target. requestUniqueMutableBackingBuffer ( minimumCapacity: oldCount + growth) != nil {
40
- target. replace ( subRange: subRange, with: insertCount, elementsOf: newValues)
41
- }
42
- else {
43
- _preconditionFailure ( " Should not get here? " )
44
- }
43
+ target. myReplace ( subRange, with: newValues)
45
44
}
46
45
47
-
48
46
@inline ( never)
49
47
public func run_PopFrontArrayGeneric( _ N: Int ) {
50
48
let orig = Array ( repeating: 1 , count: arrayCount)
@@ -55,7 +53,7 @@ public func run_PopFrontArrayGeneric(_ N: Int) {
55
53
a. append ( contentsOf: orig)
56
54
while a. count != 0 {
57
55
result += a [ 0 ]
58
- _arrayReplace ( & a. _buffer , 0 ..< 1 , EmptyCollection ( ) )
56
+ myArrayReplace ( & a, 0 ..< 1 , EmptyCollection ( ) )
59
57
}
60
58
CheckResults ( result == arrayCount, " IncorrectResults in StringInterpolation: \( result) != \( arrayCount) " )
61
59
}
0 commit comments