summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-02-19 07:00:30 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-02-19 07:00:30 -0800
commitfb4b9e9b632e88b1328a76c5636a338e73c9c746 (patch)
tree2b23df3e76a9fe96c354ee343d33205771e423b9 /struct.c
parent15b7c542dc44899e8db7addfcc2f1c1c4a188b49 (diff)
downloadtxr-fb4b9e9b632e88b1328a76c5636a338e73c9c746.tar.gz
txr-fb4b9e9b632e88b1328a76c5636a338e73c9c746.tar.bz2
txr-fb4b9e9b632e88b1328a76c5636a338e73c9c746.zip
structs: optimize struct creating functions.
We reduce consing in the structure instantiating API. * struct.c (make_struct_impl): New static function, formed from make_struct. This takes two "struct args *" arguments, for both the slot/pair property list and the BOA list. (make_struct): Now a wrapper for make_struct_impl. (struct_from_plist): Call make_struct_impl instead of make_struct, avoiding the args_get_list operation that potentially conses args on the stack into a list. Diagnosis is improved because make_struct_impl takes a self argument. (struct_from_args): Call make_struct_impl instead of make_struct.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/struct.c b/struct.c
index a2399a4d..6de9044f 100644
--- a/struct.c
+++ b/struct.c
@@ -514,9 +514,9 @@ static void call_postinitfun_chain(struct struct_type *st, val strct)
}
}
-val make_struct(val type, val plist, struct args *args)
+static val make_struct_impl(val self, val type,
+ struct args *plist, struct args *args)
{
- val self = lit("make-struct");
struct struct_type *st = stype_handle(&type, self);
cnum nslots = st->nslots, sl;
size_t size = offsetof(struct struct_inst, slot) + sizeof (val) * nslots;
@@ -546,8 +546,14 @@ val make_struct(val type, val plist, struct args *args)
call_initfun_chain(st, sinst);
- for (; plist; plist = cddr(plist))
- slotset(sinst, car(plist), cadr(plist));
+ {
+ cnum index = 0;
+ while (args_more(plist, index)) {
+ val slot = args_get(plist, &index);
+ val value = args_get(plist, &index);
+ slotset(sinst, slot, value);
+ }
+ }
if (args_more(args, 0)) {
args_decl(args_copy, max(args->fill + 1, ARGS_MIN));
@@ -570,16 +576,22 @@ val make_struct(val type, val plist, struct args *args)
return sinst;
}
+val make_struct(val type, val plist, struct args *boa)
+{
+ args_decl_list(pargs, ARGS_MIN, plist);
+ return make_struct_impl(lit("make-struct"), type, pargs, boa);
+}
+
val struct_from_plist(val type, struct args *plist)
{
- val list = args_get_list(plist);
args_decl(boa, 0);
- return make_struct(type, list, boa);
+ return make_struct_impl(lit("struct-from-plist"), type, plist, boa);
}
val struct_from_args(val type, struct args *boa)
{
- return make_struct(type, nil, boa);
+ args_decl(pargs, 0);
+ return make_struct_impl(lit("struct-from-args"), type, pargs, boa);
}
static void lazy_struct_init(val sinst, struct struct_inst *si)