mirror of
https://github.com/apple/swift-collections
synced 2026-11-25 04:37:48 +00:00
[DynamicArray] Reduce growth factor to 1.5
This commit is contained in:
2 files changed
+13
-7
No files matched your search
@@ -261,7 +261,10 @@ extension DynamicArray where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
internal func _growDynamicArrayCapacity(_ capacity: Int) -> Int {
|
||||
2 * capacity
|
||||
// A growth factor of 1.5 seems like a reasonable compromise between
|
||||
// over-allocating memory and wasting cycles on repeatedly resizing storage.
|
||||
let c = (3 &* UInt(bitPattern: capacity) &+ 1) / 2
|
||||
return Int(bitPattern: c)
|
||||
}
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
|
||||
Reference in new issue
Block a user