Improved the performance of _dictionaryBridgeFromObjectiveCConditional by only allocating a _NativeDictionaryStorage once all the items are bridged. NFC

This commit is contained in:
Maxwell Swadling
2015-11-04 14:30:31 -08:00
parent 38a08cdb43
commit e001efc741

View File

@@ -1513,7 +1513,8 @@ public func _dictionaryBridgeFromObjectiveCConditional<
_isBridgedVerbatimToObjectiveC(SwiftValue.self) ==
_isBridgedVerbatimToObjectiveC(ObjCValue.self)
var result = Dictionary<SwiftKey, SwiftValue>()
var result = [(SwiftKey, SwiftValue)]()
result.reserveCapacity(source.count)
for (key, value) in source {
// Downcast the key.
var resultKey: SwiftKey
@@ -1549,9 +1550,9 @@ public func _dictionaryBridgeFromObjectiveCConditional<
}
}
result[resultKey] = resultValue
result.append((resultKey, resultValue))
}
return result
return Dictionary(_nativeStorage: _NativeDictionaryStorage.fromArray(result))
}
#endif