summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-02-19 07:03:37 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-02-19 07:03:37 -0800
commit2e565908cf8dcc806c853d6765419546d48d1622 (patch)
tree3b5dd83fc3fe1e75b75f1787370077e6f1b415cb
parentfb4b9e9b632e88b1328a76c5636a338e73c9c746 (diff)
downloadtxr-2e565908cf8dcc806c853d6765419546d48d1622.tar.gz
txr-2e565908cf8dcc806c853d6765419546d48d1622.tar.bz2
txr-2e565908cf8dcc806c853d6765419546d48d1622.zip
struct: optimizations in new operator.
* share/txr/stdlib/struct.tl (new): Use struct-from-args and struct-from-plist whenever possible; don't use make-struct unless the syntax specifies both BOA and plist arguments. Using struct-from-plist instead of make-struct means we can now entirely avoid consing a list in compiled code. Code like (new point x 0 y 0) now allocates nothing but the struct.
-rw-r--r--share/txr/stdlib/struct.tl6
1 files changed, 4 insertions, 2 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl
index e57a82ac..5aa61d74 100644
--- a/share/txr/stdlib/struct.tl
+++ b/share/txr/stdlib/struct.tl
@@ -252,10 +252,12 @@
(tree-case spec
((atom . args)
(sys:check-struct form atom)
- ^(make-struct ',atom (list ,*qpairs) ,*args))
+ (if qpairs
+ ^(make-struct ',atom (list ,*qpairs) ,*args)
+ ^(struct-from-args ',atom ,*args)))
(atom
(sys:check-struct form atom)
- ^(make-struct ',atom (list ,*qpairs))))))
+ ^(struct-from-plist ',atom ,*qpairs)))))
(defmacro lnew (:form form spec . pairs)
(if (oddp (length pairs))