summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuh Muhten <muh.muhten@gmail.com>2019-02-25 22:55:39 -0500
committerNico Williams <nico@cryptonector.com>2019-02-26 10:49:08 -0600
commit260879a5c3959e9ecd487eb3a81cfcffa01ebe3a (patch)
tree022856c27ced93c4f97ed185ae0defab27a8932e
parent8537b93a4301ecac98fb7dad92bba9cfd17a1f37 (diff)
Rename block_bind_incremental to block_bind_referenced
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.
-rw-r--r--src/builtin.c2
-rw-r--r--src/compile.c23
-rw-r--r--src/compile.h1
3 files changed, 8 insertions, 18 deletions
diff --git a/src/builtin.c b/src/builtin.c
index 13f0717d..de56a9a1 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -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;
}
diff --git a/src/compile.c b/src/compile.c
index 6592b97e..ad632258 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -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)
@@ -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;
}
diff --git a/src/compile.h b/src/compile.h
index 8ea4d6fc..f9e8cd55 100644
--- a/src/compile.h
+++ b/src/compile.h
@@ -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);