diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-04-24 10:54:29 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-04-24 10:54:29 -0700 |
commit | 4f9808f7740f205ce92dbe463e3a5e9d42f4455b (patch) | |
tree | 687e058d52c4e685f1a4543bb99e53a9a0336e31 | |
parent | afc01b25f5e72848c87651e27af13abc1b00795f (diff) | |
download | txr-4f9808f7740f205ce92dbe463e3a5e9d42f4455b.tar.gz txr-4f9808f7740f205ce92dbe463e3a5e9d42f4455b.tar.bz2 txr-4f9808f7740f205ce92dbe463e3a5e9d42f4455b.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).
-rw-r--r-- | share/txr/stdlib/compiler.tl | 5 |
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 |