Skip to content

Commit

Permalink
u3: further optimizes u3i_edit, removing head/tail branches
Browse files Browse the repository at this point in the history
  • Loading branch information
joemfb committed May 1, 2023
1 parent 0b76a8c commit dcda46f
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions pkg/noun/imprison.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,43 +615,28 @@ u3i_edit(u3_noun big, u3_noun axe, u3_noun som)

do {
u3a_cell* big_u = u3a_to_ptr(big);
u3_noun* old = (u3_noun*)&(big_u->hed);
const c3_y bit_y = u3r_bit(dep_w, axe);

if ( c3n == u3a_is_cell(big) ) {
return u3m_bail(c3__exit);
}
else if ( c3y == u3a_is_mutable(u3R, big) ) {
*out = big;

if ( !bit_y ) {
out = &(big_u->hed);
}
else {
out = &(big_u->tel);
}

big = *out;
out = &(old[bit_y]);
big = *out;
big_u->mug_w = 0;
}
else {
u3_noun old = big;
u3_noun* hed;
u3_noun* tel;

*out = u3i_defcons(&hed, &tel);

if ( !bit_y ) {
out = hed;
big = u3k(big_u->hed);
*tel = u3k(big_u->tel);
}
else {
out = tel;
big = u3k(big_u->tel);
*hed = u3k(big_u->hed);
}

u3z(old);
u3_noun luz = big;
u3_noun* new[2];

*out = u3i_defcons(&new[0], &new[1]);
out = new[bit_y];
big = u3k(old[bit_y]);
*(new[!bit_y]) = u3k(old[!bit_y]);

u3z(luz);
}
}
while ( dep_w-- );
Expand Down

0 comments on commit dcda46f

Please sign in to comment.