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
commit19f2e3f676046a059c7d8c6b119382425de74f69 (patch)
tree3b5dd83fc3fe1e75b75f1787370077e6f1b415cb
parenta763aac8d02e6d5fc13d8c5e822bb9a84d77eabd (diff)
downloadtxr-19f2e3f676046a059c7d8c6b119382425de74f69.tar.gz
txr-19f2e3f676046a059c7d8c6b119382425de74f69.tar.bz2
txr-19f2e3f676046a059c7d8c6b119382425de74f69.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))