Skip to content

Commit

Permalink
Rename block_bind_incremental to block_bind_referenced
Browse files Browse the repository at this point in the history
block_bind_incremental is block_bind_referenced in a loop backwards. For
an 1-inst block, it does the same thing and isn't too much more
expensive, so it's not really useful to keep both.

Also, block_bind_referenced was a better name for the function.
  • Loading branch information
muhmuhten authored and nicowilliams committed Feb 26, 2019
1 parent 8537b93 commit 260879a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ int builtins_bind(jq_state *jq, block* bb) {
builtins = gen_cbinding(function_list, sizeof(function_list)/sizeof(function_list[0]), builtins);
builtins = gen_builtin_list(builtins);

*bb = block_bind_incremental(builtins, *bb, OP_IS_CALL_PSEUDO);
*bb = block_bind_referenced(builtins, *bb, OP_IS_CALL_PSEUDO);
*bb = block_drop_unreferenced(*bb);
return nerrors;
}
23 changes: 7 additions & 16 deletions src/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,20 +421,6 @@ block block_bind_library(block binder, block body, int bindflags, const char *li
return body; // We don't return a join because we don't want those sticking around...
}

// Bind binder to body, then throw it away if not referenced.
block block_bind_referenced(block binder, block body, int bindflags) {
assert(block_is_single(binder));
assert(block_has_only_binders(binder, bindflags));
bindflags |= OP_HAS_BINDING;

if (block_bind_subblock(binder, body, bindflags, 0) == 0) {
block_free(binder);
} else {
body = BLOCK(binder, body);
}
return body;
}

static inst* block_take_last(block* b) {
inst* i = b->last;
if (i == 0)
Expand All @@ -452,13 +438,18 @@ static inst* block_take_last(block* b) {

// Binds a sequence of binders, which *must not* alrady be bound to each other,
// to body, throwing away unreferenced defs
block block_bind_incremental(block binder, block body, int bindflags) {
block block_bind_referenced(block binder, block body, int bindflags) {
assert(block_has_only_binders(binder, bindflags));
bindflags |= OP_HAS_BINDING;

inst* curr;
while ((curr = block_take_last(&binder))) {
body = block_bind_referenced(inst_block(curr), body, bindflags);
block b = inst_block(curr);
if (block_bind_subblock(b, body, bindflags, 0) == 0) {
block_free(b);
} else {
body = BLOCK(b, body);
}
}
return body;
}
Expand Down
1 change: 0 additions & 1 deletion src/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ int block_is_funcdef(block b);
int block_is_single(block b);
block block_bind_library(block binder, block body, int bindflags, const char* libname);
block block_bind_referenced(block binder, block body, int bindflags);
block block_bind_incremental(block binder, block body, int bindflags);
block block_bind_self(block binder, int bindflags);
block block_drop_unreferenced(block body);

Expand Down

0 comments on commit 260879a

Please sign in to comment.