summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-04-24 10:54:29 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-04-24 10:54:29 -0700
commit4e32c272c818c01577f42a63e09b01f8b6257fe4 (patch)
tree687e058d52c4e685f1a4543bb99e53a9a0336e31 /share
parente186650c97103dd3c54621af7f7e2ab5ac07a70a (diff)
downloadtxr-4e32c272c818c01577f42a63e09b01f8b6257fe4.tar.gz
txr-4e32c272c818c01577f42a63e09b01f8b6257fe4.tar.bz2
txr-4e32c272c818c01577f42a63e09b01f8b6257fe4.zip
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).
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/compiler.tl5
1 files changed, 4 insertions, 1 deletions
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