From 2e565908cf8dcc806c853d6765419546d48d1622 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 19 Feb 2019 07:03:37 -0800 Subject: 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. --- share/txr/stdlib/struct.tl | 6 ++++-- 1 file 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)) -- cgit v1.2.3