summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-10-16 07:57:15 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-10-16 07:57:15 -0700
commite91d406a7ff82b8dfd57b3d84065597b640328db (patch)
tree763f4eb9a23d77efe9905c1accd3b2d77fec2b18 /lib.c
parent8c907a932436a8bdc2c52d2a28e14115df525654 (diff)
downloadtxr-e91d406a7ff82b8dfd57b3d84065597b640328db.tar.gz
txr-e91d406a7ff82b8dfd57b3d84065597b640328db.tar.bz2
txr-e91d406a7ff82b8dfd57b3d84065597b640328db.zip
copy-cons: more efficient; copies lconses.
* lib.c (copy_cons): Rewrite to copy the object in a more low-level way, rather than going through the accessors and constructors. Now copies LCONS as LCONS, including its update function. * txr.1: copy-cons re-documented.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index b6f22971..aa5fcde8 100644
--- a/lib.c
+++ b/lib.c
@@ -8160,9 +8160,19 @@ val alist_nremove1(val list, val key)
return list;
}
-val copy_cons(val c)
+val copy_cons(val cell)
{
- return cons(car(c), cdr(c));
+ switch (type(cell)) {
+ case CONS:
+ case LCONS:
+ {
+ val obj = make_obj();
+ *obj = *cell;
+ return obj;
+ }
+ default:
+ type_mismatch(lit("copy-cons: ~s is not a cons"), cell, nao);
+ }
}
val copy_alist(val list)