summaryrefslogtreecommitdiffstats
path: root/args.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-03-09 06:12:38 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-03-09 06:12:38 -0800
commit55432c44257c340b7dc6ba565e49d6b584a9692c (patch)
tree4f3004c9015a310a1b3a08b8e7adfe782891b549 /args.h
parent968e13cbbda2e9fc8a7e8d91cd35d4ac93c695b9 (diff)
downloadtxr-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 'args.h')
-rw-r--r--args.h12
1 files changed, 4 insertions, 8 deletions
diff --git a/args.h b/args.h
index 3ea94186..76aa10a1 100644
--- a/args.h
+++ b/args.h
@@ -134,14 +134,15 @@ INLINE int args_two_more(struct args *args, cnum index)
cdr(args->list);
}
-void args_normalize(struct args *args, cnum fill);
+void args_normalize_exact(struct args *args, cnum fill);
+void args_normalize_least(struct args *args, cnum fill);
void args_normalize_fill(struct args *args, cnum minfill, cnum maxfill);
INLINE val args_get_list(struct args *args)
{
if (args->fill == 0)
return z(args->list);
- args_normalize(args, 0);
+ args_normalize_exact(args, 0);
return z(args->list);
}
@@ -149,7 +150,7 @@ INLINE val args_get_rest(struct args *args, cnum index)
{
if (args->fill == index)
return z(args->list);
- args_normalize(args, index);
+ args_normalize_exact(args, index);
return z(args->list);
}
@@ -176,11 +177,6 @@ INLINE val args_get(struct args *args, cnum *arg_index)
return pop(&args->list);
}
-INLINE void args_clear(struct args *args)
-{
- args->fill = 0;
-}
-
INLINE cnum args_count(struct args *args)
{
return args->fill + c_num(length_list(args->list));