Change APPEND opcode to directly modify a variable.

Avoids a big O(n^2) loop in constructing arrays. Fixes #61.
This commit is contained in:
Stephen Dolan committed 2013-01-03 12:51:33 +00:00
1 parent fb84541e11
commit c013b557a2
3 files changed
+8 -9

No files matched your search

+1 -5
View File
@@ -292,11 +292,7 @@ block gen_collect(block expr) {
gen_noop(), OP_HAS_VARIABLE);
block c = BLOCK(gen_op_simple(DUP), gen_const(jv_array()), array_var);
block tail = BLOCK(gen_op_simple(DUP),
gen_op_var_bound(LOADV, array_var),
gen_op_simple(SWAP),
gen_op_simple(APPEND),
gen_op_var_bound(STOREV, array_var),
block tail = BLOCK(gen_op_var_bound(APPEND, array_var),
gen_op_simple(BACKTRACK));
return BLOCK(c,
+6 -3
View File
@@ -236,9 +236,12 @@ jv jq_next() {
case APPEND: {
// FIXME paths
jv v = stack_pop().value;
jv array = stack_pop().value;
array = jv_array_append(array, v);
stack_push(stackval_root(array));
uint16_t level = *pc++;
uint16_t vidx = *pc++;
frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level);
jv* var = frame_local_var(fp, vidx);
assert(jv_get_kind(*var) == JV_KIND_ARRAY);
*var = jv_array_append(*var, v);
break;
}
+1 -1
View File
@@ -12,7 +12,7 @@ OP(FORK, BRANCH, 0, 0)
OP(JUMP, BRANCH, 0, 0)
OP(JUMP_F,BRANCH, 1, 0)
OP(BACKTRACK, NONE, 0, 0)
OP(APPEND, NONE, 2, 1)
OP(APPEND, VARIABLE,1, 0)
OP(INSERT, NONE, 4, 2)
OP(GETPATH, NONE, 2, 1)