summaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-04-05 15:22:37 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-04-05 15:22:37 -0700
commit5ca3693a7b5d65fd5aa67c737e7a60b457db2281 (patch)
tree83c85bce2661b588a0445619fc58f121359c4468 /share
parent06ce08dc2c0d2db522c5f6293cf9a28c2c22d24a (diff)
downloadtxr-5ca3693a7b5d65fd5aa67c737e7a60b457db2281.tar.gz
txr-5ca3693a7b5d65fd5aa67c737e7a60b457db2281.tar.bz2
txr-5ca3693a7b5d65fd5aa67c737e7a60b457db2281.zip
compiler: better shared test for sys:switch.
* share/txr/stdlib/compiler.tl (compiler comp-switch): The shared test here is both inaccurate and O(n^2). It tests that all the remaining branches of the code are tails of the first branch. However, this is not strict enough: we need to also test that the tails are in their order of appearance. We can do that in O(n) time.
Diffstat (limited to 'share')
-rw-r--r--share/txr/stdlib/compiler.tl7
1 files changed, 6 insertions, 1 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl
index cbd2b6ee..3d906866 100644
--- a/share/txr/stdlib/compiler.tl
+++ b/share/txr/stdlib/compiler.tl
@@ -524,7 +524,12 @@
(mac-param-bind form (op idx-form cases-vec) form
(let* ((ncases (len cases-vec))
(cs (and (plusp ncases) (conses [cases-vec 0])))
- (shared (and cs (all [cases-vec 1..:] (op memq @1 cs))))
+ (shared (and cs
+ (let ((c cs)
+ (d (cdr (list-vec cases-vec))))
+ (whilet ((m (if d (memq (pop d) c))))
+ (set c m))
+ (null d))))
(cases (if shared
(let ((cs-nil ^(,*cs nil)))
[mapcar ldiff cs-nil (cdr cs-nil)])