mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[benchmark] PopFrontGeneric - Replace protocol with minimal implementation
_ArrayBufferProtocol's visiblity will be changed to internal. Replace with a minimal implementation for this benchmark. rdar://27261449
This commit is contained in:
@@ -17,34 +17,32 @@ let arrayCount = 1024
|
||||
|
||||
// This test case exposes rdar://17440222 which caused rdar://17974483 (popFront
|
||||
// being really slow).
|
||||
protocol MyArrayBufferProtocol : MutableCollection, RandomAccessCollection {
|
||||
associatedtype Element
|
||||
|
||||
func _arrayReplace<B: _ArrayBufferProtocol, C: Collection
|
||||
mutating func myReplace<C>(
|
||||
_ subRange: Range<Int>,
|
||||
with newValues: C
|
||||
) where C : Collection, C.Iterator.Element == Element
|
||||
}
|
||||
|
||||
extension Array : MyArrayBufferProtocol {
|
||||
mutating func myReplace<C>(
|
||||
_ subRange: Range<Int>,
|
||||
with newValues: C
|
||||
) where C : Collection, C.Iterator.Element == Element {
|
||||
replaceSubrange(subRange, with: newValues)
|
||||
}
|
||||
}
|
||||
|
||||
func myArrayReplace<B: MyArrayBufferProtocol, C: Collection
|
||||
where C.Iterator.Element == B.Element, B.Index == Int
|
||||
>(
|
||||
_ target: inout B, _ subRange: Range<Int>, _ newValues: C
|
||||
) {
|
||||
_precondition(
|
||||
subRange.lowerBound >= 0,
|
||||
"Array replace: subRange start is negative")
|
||||
|
||||
_precondition(
|
||||
subRange.upperBound <= target.endIndex,
|
||||
"Array replace: subRange extends past the end")
|
||||
|
||||
let oldCount = target.count
|
||||
let eraseCount = subRange.count
|
||||
let insertCount = numericCast(newValues.count) as Int
|
||||
let growth = insertCount - eraseCount
|
||||
|
||||
if target.requestUniqueMutableBackingBuffer(minimumCapacity: oldCount + growth) != nil {
|
||||
target.replace(subRange: subRange, with: insertCount, elementsOf: newValues)
|
||||
}
|
||||
else {
|
||||
_preconditionFailure("Should not get here?")
|
||||
}
|
||||
target.myReplace(subRange, with: newValues)
|
||||
}
|
||||
|
||||
|
||||
@inline(never)
|
||||
public func run_PopFrontArrayGeneric(_ N: Int) {
|
||||
let orig = Array(repeating: 1, count: arrayCount)
|
||||
@@ -55,7 +53,7 @@ public func run_PopFrontArrayGeneric(_ N: Int) {
|
||||
a.append(contentsOf: orig)
|
||||
while a.count != 0 {
|
||||
result += a[0]
|
||||
_arrayReplace(&a._buffer, 0..<1, EmptyCollection())
|
||||
myArrayReplace(&a, 0..<1, EmptyCollection())
|
||||
}
|
||||
CheckResults(result == arrayCount, "IncorrectResults in StringInterpolation: \(result) != \(arrayCount)")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user