ref: 871bf897b05b137adffa3b753ea490ee03ca7bf0
parent: 86ab9603ae87df4052e4b6a92b912683f7d5d7fe
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Jan 27 17:52:26 EST 2016
Make it clear that we're growing exponentially.
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -57,6 +57,8 @@
var buckets : bucket[32] /* excessive */
+extern const put : (str : byte[:], args : ... -> void)
+
type slheader = struct
cap : size /* capacity in bytes */
magic : size /* magic check value */
@@ -175,7 +177,13 @@
-> (sl castto(@a#))[:len]
;;
- new = slalloc(len)
+ /* grow in factors of 1.5 */
+ cap = max(Align, cap)
+ while cap < len
+ cap += (cap >> 1)
+ ;;
+
+ new = slalloc(cap)
n = min(len, sl.len)
for var i = 0; i < n; i++
new[i] = sl[i]
@@ -183,7 +191,7 @@
if sl.len > 0
slfree(sl)
;;
- -> new
+ -> new[:len]
}
/* Grows a slice, filling new entries with zero bytes */