ref: e506b713ad0766bf7eb182325cba64fd6931c1cc
parent: 4fd76bb3f5d16488d7b50a5ef1b7674537889e06
author: andrewc <andrewchamberss@gmail.com>
date: Fri Feb 5 12:32:18 EST 2016
change slgrow to take a pointer
--- a/lib/regex/compile.myr
+++ b/lib/regex/compile.myr
@@ -352,7 +352,7 @@
/* appends an instructon to an re program */
const append = {re, insn
if re.proglen == re.prog.len
- re.prog = std.slgrow(re.prog, std.max(1, 2*re.proglen))
+ std.slgrow(&re.prog, std.max(1, 2*re.proglen))
;;
re.prog[re.proglen] = insn
re.proglen++
--- a/lib/std/alloc.myr
+++ b/lib/std/alloc.myr
@@ -33,7 +33,7 @@
generic slalloc : (len : size -> @a[:])
generic slzalloc : (len : size -> @a[:])
- generic slgrow : (sl : @a[:], len : size -> @a[:])
+ generic slgrow : (sl : @a[:]#, len : size -> @a[:])
generic slzgrow : (sl : @a[:]#, len : size -> @a[:])
generic slfree : (sl : @a[:] -> void)
@@ -163,7 +163,7 @@
}
/* Grows a slice */
-generic slgrow = {sl : @a[:], len
+generic slgrow = {sl : @a[:]#, len
var cap
var new
var n
@@ -170,11 +170,12 @@
/* if the slice doesn't need a bigger bucket, we don't need to realloc. */
cap = 0
- if sl castto(byte#) != Zsliceptr
- cap = slcap(sl castto(byte#))
+ if sl# castto(byte#) != Zsliceptr
+ cap = slcap(sl# castto(byte#))
;;
if cap >= allocsz(len*sizeof(@a))
- -> (sl castto(@a#))[:len]
+ sl# = (sl# castto(@a#))[:len]
+ -> sl#
;;
/* grow in factors of 1.5 */
@@ -184,14 +185,15 @@
;;
new = slalloc(cap)
- n = min(len, sl.len)
+ n = min(len, sl#.len)
for var i = 0; i < n; i++
- new[i] = sl[i]
+ new[i] = sl#[i]
;;
- if sl.len > 0
- slfree(sl)
+ if sl#.len > 0
+ slfree(sl#)
;;
- -> new[:len]
+ sl# = new[:len]
+ -> sl#
}
/* Grows a slice, filling new entries with zero bytes */
@@ -200,7 +202,7 @@
var base
oldlen = sl#.len
- sl# = slgrow(sl#, len)
+ slgrow(sl, len)
base = sl# castto(byte#) castto(intptr)
if oldlen < len
memfill(sl#[oldlen:] castto(byte#), 0, (len - oldlen)*sizeof(@a))
--- a/lib/std/bigint.myr
+++ b/lib/std/bigint.myr
@@ -728,7 +728,7 @@
break
;;
;;
- a.dig = slgrow(a.dig, i)
+ slgrow(&a.dig, i)
if i == 0
a.sign = 0
elif a.sign == 0
--- a/lib/std/sljoin.myr
+++ b/lib/std/sljoin.myr
@@ -9,7 +9,7 @@
var len
len = dst#.len
- dst# = slgrow(dst#, len + src.len)
+ slgrow(dst, len + src.len)
slcp(dst#[len:], src)
-> dst#
}
--- a/lib/std/slpop.myr
+++ b/lib/std/slpop.myr
@@ -9,6 +9,6 @@
var elt
elt = sl[sl.len - 1]
- sl = slgrow(sl, sl.len - 1)
+ slgrow(&sl, sl.len - 1)
-> (elt, sl)
}
--- a/lib/std/slpush.myr
+++ b/lib/std/slpush.myr
@@ -14,7 +14,7 @@
a bucket boundary, this is effectively
growing the slice by powers of two.
*/
- sl# = slgrow(sl#, sl#.len + 1)
+ slgrow(sl, sl#.len + 1)
sl#[sl#.len - 1] = elt
-> sl#
}
--- a/lib/std/slput.myr
+++ b/lib/std/slput.myr
@@ -11,7 +11,7 @@
var len
len = sl.len
- sl = slgrow(sl, sl.len + 1)
+ slgrow(&sl, sl.len + 1)
for i = len - 1; i >= idx; i--
sl[i + 1] = sl[i]
;;
--- a/lib/std/slurp.myr
+++ b/lib/std/slurp.myr
@@ -39,7 +39,7 @@
len += n
if len + 2*n >= bufsz
bufsz *= 2
- buf = slgrow(buf, bufsz)
+ slgrow(&buf, bufsz)
;;
| `Fail e:
slfree(buf)
--- a/lib/std/strbuf.myr
+++ b/lib/std/strbuf.myr
@@ -101,7 +101,7 @@
-> false
;;
while sb.buf.len < sb.len + len
- sb.buf = slgrow(sb.buf, 2*sb.buf.len)
+ slgrow(&sb.buf, 2*sb.buf.len)
;;
-> true
}
--- a/mbld/deps.myr
+++ b/mbld/deps.myr
@@ -173,7 +173,7 @@
addusedep(b, ds, g, path, l, lnum)
;;
;;
- ds.depstk = std.slgrow(ds.depstk, ds.depstk.len - 1)
+ std.slgrow(&ds.depstk, ds.depstk.len - 1)
std.htput(g.seen, path, false)
std.htput(g.done, path, true)
}
--- a/test/slgrow.myr
+++ b/test/slgrow.myr
@@ -6,7 +6,7 @@
sl = std.slalloc(42)
sl[0] = 12
- sl = std.slgrow(sl, 123)
+ std.slgrow(&sl, 123)
sl[122] = 30
std.exit(sl[0] + sl[122])
}