ref: f8b121ae9b3e57bbca8304676d417f680ad26f7a
parent: aec1d8a65052364f4946556e36d276b34e62bdcf
author: Ori Bernstein <ori@markovcorp.com>
date: Fri Feb 9 06:05:51 EST 2018
Fix confusingness with byte sizes/element counts. This was probably buggy.
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -122,7 +122,7 @@
/* Grows a slice */
generic slgrow = {sl : @a[:]#, len
- var cap
+ var cap, nel
var new
var n
@@ -131,18 +131,18 @@
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