mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-11 04:48:00 +03:00
use road stack instead of heap vector in reel
This commit is contained in:
parent
6125ac4fe4
commit
8bc148acc3
@ -12,34 +12,25 @@
|
||||
u3_noun pro = u3k(u3x_at(u3x_sam_3, b));
|
||||
if ( u3_nul != a ) {
|
||||
u3j_site sit_u;
|
||||
u3_noun* top;
|
||||
u3_noun i, t = a;
|
||||
c3_w j_w, len_w = 0, all_w = 89, pre_w = 55;
|
||||
u3_noun* vec = u3a_malloc(all_w * sizeof(u3_noun));
|
||||
c3_w len_w = 0;
|
||||
|
||||
// stuff list into an array
|
||||
// push list onto road stack
|
||||
do {
|
||||
if ( c3n == u3r_cell(t, &i, &t) ) {
|
||||
u3a_free(vec);
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
else {
|
||||
if ( len_w == all_w ) {
|
||||
// grow vec fib-wise
|
||||
all_w += pre_w;
|
||||
pre_w = len_w;
|
||||
vec = u3a_realloc(vec, all_w * sizeof(u3_noun));
|
||||
}
|
||||
vec[len_w++] = i;
|
||||
}
|
||||
u3x_cell(t, &i, &t);
|
||||
top = (c3_w*) u3a_push(sizeof(u3_noun));
|
||||
*top = i;
|
||||
++len_w;
|
||||
} while ( u3_nul != t );
|
||||
|
||||
// now we can iterate backwards
|
||||
u3j_gate_prep(&sit_u, u3k(b));
|
||||
for ( j_w = len_w; j_w > 0; ) {
|
||||
pro = u3j_gate_slam(&sit_u, u3nc(u3k(vec[--j_w]), pro));
|
||||
while ( len_w-- > 0 ) {
|
||||
top = u3a_peek(sizeof(u3_noun));
|
||||
u3a_pop(sizeof(u3_noun));
|
||||
pro = u3j_gate_slam(&sit_u, u3nc(u3k(*top), pro));
|
||||
}
|
||||
u3j_gate_lose(&sit_u);
|
||||
u3a_free(vec);
|
||||
}
|
||||
return pro;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user