From 260879a5c3959e9ecd487eb3a81cfcffa01ebe3a Mon Sep 17 00:00:00 2001 From: Muh Muhten Date: Mon, 25 Feb 2019 22:55:39 -0500 Subject: [PATCH] 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. --- src/builtin.c | 2 +- src/compile.c | 23 +++++++---------------- src/compile.h | 1 - 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/builtin.c b/src/builtin.c index 13f0717deb..de56a9a197 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 6592b97ed9..ad632258e3 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 8ea4d6fcf4..f9e8cd5514 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);