shithub: mc

Download patch

ref: dcd6fad70720c2c8baa5e0096f2b14e45e9aa447
parent: dbf04d054d0fc04385c766ced8e0f3b3edd120e8
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Mar 10 14:19:18 EST 2018

Don't overallocate.

	We were allocating data that was a bit too big.

--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -131,7 +131,8 @@
 	if (sl# : byte#) != Zsliceptr
 		cap = slcap((sl# : byte#))
 	;;
-	if cap >= allocsz(len*sizeof(@a)) + align(sizeof(slheader), Align)
+	if cap >= len*sizeof(@a)
+		/* cast to pointer to work around bounds check */
 		sl# = (sl# : @a#)[:len]
 		-> sl#
 	;;
@@ -139,7 +140,7 @@
 	/* grow in factors of 1.5 */
 	nel = sl#.len
 	while nel < len
-		nel = nel * 2 + 2
+		nel += (nel >> 2) + 1
 	;;
 
 	new = slalloc(nel)
--- a/lib/std/bytealloc.myr
+++ b/lib/std/bytealloc.myr
@@ -125,7 +125,6 @@
 const bytealloc = {sz
 	var bkt, p
 
-	sz += 8
 	if sz <= Bktmax
 		bkt = &buckets[bktnum(sz)]
 		lock(memlck)