From ecb9c23e0811e219ac622133add5c1524c35e649 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Mon, 28 Sep 2020 11:30:42 -0700 Subject: [PATCH] u3: adds u3i_slab_from(), removes unnecessary uses of u3r_chop() --- pkg/urbit/include/noun/imprison.h | 5 +++++ pkg/urbit/jets/c/cat.c | 3 +-- pkg/urbit/jets/c/con.c | 5 +---- pkg/urbit/jets/c/dis.c | 5 +---- pkg/urbit/jets/c/mix.c | 7 +++---- pkg/urbit/noun/imprison.c | 12 ++++++++++++ 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pkg/urbit/include/noun/imprison.h b/pkg/urbit/include/noun/imprison.h index 7c5e55c0b..577cec02f 100644 --- a/pkg/urbit/include/noun/imprison.h +++ b/pkg/urbit/include/noun/imprison.h @@ -32,6 +32,11 @@ void u3i_slab_bare(u3i_slab* sab_u, c3_g met_g, c3_w len_w); + /* u3i_slab_from(): configure bloq-length slab, initialize with [a]. + */ + void + u3i_slab_from(u3i_slab* sab_u, u3_atom a, c3_g met_g, c3_w len_w); + /* u3i_slab_grow(): resize slab, reallocating as necessary. */ void diff --git a/pkg/urbit/jets/c/cat.c b/pkg/urbit/jets/c/cat.c index 0851ddc7c..2648c2303 100644 --- a/pkg/urbit/jets/c/cat.c +++ b/pkg/urbit/jets/c/cat.c @@ -25,9 +25,8 @@ } else { u3i_slab sab_u; - u3i_slab_init(&sab_u, a_g, all_w); + u3i_slab_from(&sab_u, b, a_g, all_w); - u3r_chop(a_g, 0, lew_w, 0, sab_u.buf_w, b); u3r_chop(a_g, 0, ler_w, lew_w, sab_u.buf_w, c); return u3i_slab_mint(&sab_u); diff --git a/pkg/urbit/jets/c/con.c b/pkg/urbit/jets/c/con.c index 09db8cbc4..9fa8df142 100644 --- a/pkg/urbit/jets/c/con.c +++ b/pkg/urbit/jets/c/con.c @@ -20,10 +20,7 @@ c3_w len_w = c3_max(lna_w, lnb_w); c3_w i_w; u3i_slab sab_u; - - u3i_slab_init(&sab_u, 5, len_w); - - u3r_chop(5, 0, lna_w, 0, sab_u.buf_w, a); + u3i_slab_from(&sab_u, a, 5, len_w); for ( i_w = 0; i_w < lnb_w; i_w++ ) { sab_u.buf_w[i_w] |= u3r_word(i_w, b); diff --git a/pkg/urbit/jets/c/dis.c b/pkg/urbit/jets/c/dis.c index cdeae3dd2..a0f478a94 100644 --- a/pkg/urbit/jets/c/dis.c +++ b/pkg/urbit/jets/c/dis.c @@ -20,10 +20,7 @@ c3_w len_w = c3_max(lna_w, lnb_w); c3_w i_w; u3i_slab sab_u; - - u3i_slab_init(&sab_u, 5, len_w); - - u3r_chop(5, 0, lna_w, 0, sab_u.buf_w, a); + u3i_slab_from(&sab_u, a, 5, len_w); for ( i_w = 0; i_w < len_w; i_w++ ) { sab_u.buf_w[i_w] &= (i_w >= lnb_w) ? 0 : u3r_word(i_w, b); diff --git a/pkg/urbit/jets/c/mix.c b/pkg/urbit/jets/c/mix.c index bc013dabc..ccb008c05 100644 --- a/pkg/urbit/jets/c/mix.c +++ b/pkg/urbit/jets/c/mix.c @@ -20,11 +20,10 @@ c3_w len_w = c3_max(lna_w, lnb_w); c3_w i_w; u3i_slab sab_u; + u3i_slab_from(&sab_u, a, 5, len_w); - u3i_slab_init(&sab_u, 5, len_w); - - u3r_chop(5, 0, lna_w, 0, sab_u.buf_w, a); - + // XX use u3r_chop for XOR? + // for ( i_w = 0; i_w < lnb_w; i_w++ ) { sab_u.buf_w[i_w] ^= u3r_word(i_w, b); } diff --git a/pkg/urbit/noun/imprison.c b/pkg/urbit/noun/imprison.c index 2ae4dd70e..13198d209 100644 --- a/pkg/urbit/noun/imprison.c +++ b/pkg/urbit/noun/imprison.c @@ -155,6 +155,18 @@ u3i_slab_bare(u3i_slab* sab_u, c3_g met_g, c3_w len_w) u3t_off(mal_o); } +/* u3i_slab_from(): configure bloq-length slab, initialize with [a]. +*/ +void +u3i_slab_from(u3i_slab* sab_u, u3_atom a, c3_g met_g, c3_w len_w) +{ + u3i_slab_bare(sab_u, met_g, len_w); + + // copies [a], zero-initializes any additional space + // + u3r_words(0, sab_u->wor_w, sab_u->buf_w, a); +} + /* u3i_slab_grow(): resize slab, reallocating as necessary. */ void