diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-03-09 06:12:38 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-03-09 06:12:38 -0800 |
commit | 55432c44257c340b7dc6ba565e49d6b584a9692c (patch) | |
tree | 4f3004c9015a310a1b3a08b8e7adfe782891b549 /struct.c | |
parent | 968e13cbbda2e9fc8a7e8d91cd35d4ac93c695b9 (diff) | |
download | txr-55432c44257c340b7dc6ba565e49d6b584a9692c.tar.gz txr-55432c44257c340b7dc6ba565e49d6b584a9692c.tar.bz2 txr-55432c44257c340b7dc6ba565e49d6b584a9692c.zip |
args: overhaul for clarity and reduced consing.
* args.c (args_normalize): Renamed to args_normalize_exact,
because this tries to split the arguments between an exact
array fill quantity and trailing list. Not all places using
this function actually need an exact fill, which causes
unnecessary consing when args->fill is reduced in order to
move items to args->list.
(args_normalize_least): New function. Variant of
args_normalize that can be used by functions which only
require a minimum fill.
(args_normalize_fill): Use args_normalize_least rather than
args_normalize_exact. This reduces consing in generic_funcall,
in handling variadic calls where arrayed arguments have been
supplied for trailing parameters.
* args.h (args_normalize): Renamed to args_normalize_exact.
(args_normalize_least): Declared.
(args_get_list, args_get_rest): Use args_normalize_exact.
(args_clear): Inline function removed. Was used only in one
place in generic_funcall and is no longer.
* eval.c (gather_free_refs): Use args_normalize_least.
(prod_common): Use args_normalize_exact.
* ffi.c (ffi_call_wrap): Use args_normalize_least.
* lib.c (generic_funcall): Use args_normalize_least in switch
statement that handles various callable non-function objects.
When copying args, ensure that there are ARGS_MIN.
A different strategy is used for producing the trailing args
for variadic calls, further reducing consing. Rather than
normalize the args to the fixed number, and then set
args->fill to zero so that args contains just the list, we use
args_cat_zap_from to create a copy of the args in which the
fixed ones are trimmed out. The resulting args is not
renormalized to be purely a list so no consing or list traversal
takes place. If the rebalancing is needed, the called
function will have to do it.
(dwim_set): Streamline the code that handles hashes assigned
via two or three args.
* struct.c (method_args_fun, umethod_args_fun): Use
args_normalize_exact.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -1297,7 +1297,7 @@ static val method_args_fun(val env, varg args) args_decl(args_call, max(args->fill + 1 + ca_len, ARGS_MIN)); args_add(args_call, strct); args_add_list(args_call, curried_args); - args_normalize(args_call, ca_len + 1); + args_normalize_exact(args_call, ca_len + 1); args_cat_zap(args_call, args); return generic_funcall(fun, args_call); } @@ -1379,7 +1379,7 @@ static val umethod_args_fun(val env, struct args *args) args_decl(args_call, max(args->fill + ca_len, ARGS_MIN)); args_add(args_call, strct); args_add_list(args_call, curried_args); - args_normalize(args_call, ca_len + 1); + args_normalize_exact(args_call, ca_len + 1); args_cat_zap_from(args_call, args, index); struct struct_inst *si = struct_handle(strct, self); |