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:
Erik Eckstein
2014-10-01 14:52:25 +00:00
parent b833355506
commit cd4b943897

View File

@@ -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
}