u3: adds u3i_slab_from(), removes unnecessary uses of u3r_chop()

This commit is contained in:
Joe Bryan 2020-09-28 11:30:42 -07:00
parent ea9328a4db
commit ecb9c23e08
6 changed files with 23 additions and 14 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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