summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2018-02-09 11:05:51 -0800
committerOri Bernstein <ori@markovcorp.com>2018-02-09 11:05:51 -0800
commitf8b121ae9b3e57bbca8304676d417f680ad26f7a (patch)
treedfcc6f8765eb256fb29dda242f9ccded2ed856ee
parentaec1d8a65052364f4946556e36d276b34e62bdcf (diff)
downloadmc-f8b121ae9b3e57bbca8304676d417f680ad26f7a.tar.gz
Fix confusingness with byte sizes/element counts.
This was probably buggy.
-rw-r--r--lib/std/alloc.myr12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/alloc.myr b/lib/std/alloc.myr
index 576def4..bc26a1c 100644
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -122,7 +122,7 @@ generic slfree = {sl
/* Grows a slice */
generic slgrow = {sl : @a[:]#, len
- var cap
+ var cap, nel
var new
var n
@@ -131,18 +131,18 @@ generic slgrow = {sl : @a[:]#, len
if (sl# : byte#) != Zsliceptr
cap = slcap((sl# : byte#))
;;
- if cap >= allocsz(len*sizeof(@a))
+ if cap >= allocsz(len*sizeof(@a)) + align(sizeof(slheader), Align)
sl# = (sl# : @a#)[:len]
-> sl#
;;
/* grow in factors of 1.5 */
- cap = max(Align, cap)
- while cap < len
- cap += (cap >> 1)
+ nel = sl#.len
+ while nel < len
+ nel = nel * 2 + 2
;;
- new = slalloc(cap)
+ new = slalloc(nel)
n = min(len, sl#.len)
memblit((new : byte#), (sl# : byte#), n * sizeof(@a))
if sl#.len > 0