From 4e32c272c818c01577f42a63e09b01f8b6257fe4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 24 Apr 2021 10:54:29 -0700 Subject: compiler: optimize zero and one item quasiliterals. * share/txr/stdlib/compiler.tl (expand-quasi): Do not emit sys:fmt-join call unconditionally. If expand-quasi yields a list of one expression, we can just yield that expression. If the list is empty, we can yield a mutable empty string. (That case will not arise via `` because that converts to "" at read time, but code that generates quasiliteral syntax might have an empty case, and expect a mutable string in all cases). --- share/txr/stdlib/compiler.tl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'share') diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index baf5985f..a395347d 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1828,7 +1828,10 @@ (defun expand-quasi (form) (let ((qa (expand-quasi-args form))) - ^(sys:fmt-join ,*qa))) + (cond + ((cdr qa) ^(sys:fmt-join ,*qa)) + (qa (car qa)) + (t '(mkstring 0))))) (defun expand-dohash (form) (mac-param-bind form (op (key-var val-var hash-form : res-form) . body) form -- cgit v1.2.3