mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Don't call reserveCapacity if constructing an empty uninitalized array.
This speeds up empty array literals and fixes the performance regression in the Havlak benchmark. See <rdar://problem/18480488> PerfReg: Havlak - Megaclang - r353047-r353195 - 3x Swift SVN r22427
This commit is contained in:
@@ -352,7 +352,11 @@ extension ${Self} : ArrayType {
|
||||
internal init(_uninitializedCount count: Int) {
|
||||
_precondition(count >= 0, "Can't construct ${Self} with count < 0")
|
||||
_buffer = _Buffer()
|
||||
reserveCapacity(count)
|
||||
|
||||
// Performance optimization: avoid reserveCapacity call if not needed.
|
||||
if count > 0 {
|
||||
reserveCapacity(count)
|
||||
}
|
||||
_buffer.count = count
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user