[DynamicArray] Reduce growth factor to 1.5

This commit is contained in:
Karoy Lorentey committed 2025-08-29 17:12:19 -07:00
1 parent 39dc431dbc
commit 3ff65774bd
2 files changed
+13 -7

No files matched your search

+4 -1
View File
@@ -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 {