diff options
Diffstat (limited to 'examples/vec.fwd')
| -rw-r--r-- | examples/vec.fwd | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/vec.fwd b/examples/vec.fwd index 903c3e7..6950c2a 100644 --- a/examples/vec.fwd +++ b/examples/vec.fwd @@ -25,19 +25,21 @@ next_s_vec(u64 s, (u64) ok) reserve_vec(vec v, u64 c, (vec) ok) { v => [n => n, s => s, buf => buf]; - n + c => nn; /* expand if we run out of space */ - if nn > s { + if c > s { next_s_vec(s) => s; /* note that fwdrealloc creates a new closure, meaning that it * takes ownership of v.buf, so we can't back out and do a * single ok(v) at the end of the function */ fwdrealloc(buf, s * sizeof(i64)) => nbuf; - ok([nn => n, s => s, nbuf => buf] vec); + ok([c => n, s => s, nbuf => buf] vec); } else { - ok([nn => n, s => s, buf => buf] vec); + /* if this were a generic vector we'd have to worry about + * destroying the elements, but since we're just dealing with + * integers this is fine */ + ok([c => n, s => s, buf => buf] vec); } } @@ -142,7 +144,7 @@ check_vec(i64 i, i64 n, vec v, (vec) ok) main() { init_vec(0 as u64) => vec v; - populate_vec(0, 10, v) => vec v; - check_vec(0, 10, v) => vec v; + populate_vec(0, 1000000, v) => vec v; + check_vec(0, 1000000, v) => vec v; destroy_vec(v); } |
