summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-01-20 18:59:57 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-01-20 18:59:57 -0800
commitd30af5639c1a3a27452a7cd63c6f91201eac687b (patch)
tree9923feff7556bb6aa28e43e610d5bfa1c58c975e
parentac1405bd21d70414ea508e60f1542b4a5551f016 (diff)
downloadtxr-d30af5639c1a3a27452a7cd63c6f91201eac687b.tar.gz
txr-d30af5639c1a3a27452a7cd63c6f91201eac687b.tar.bz2
txr-d30af5639c1a3a27452a7cd63c6f91201eac687b.zip
match-case: eliminate useless initial flag test.
* share/txr/stdlib/match.tl (match-case): The first case should not test the flag variable, the variable is false. This compiles to a useless if instruction and unreachable code. I tried writing a peephole rule against that instruction sequence in an experimental peephole optimizer, but across the entire code, it only matched in code in compiler.tl arising out of match-case, so it is better to squash this at the source. I won't commit the peephole optimizer until it comes up with something that isn't better fixed elsewhere.
-rw-r--r--share/txr/stdlib/match.tl5
1 files changed, 3 insertions, 2 deletions
diff --git a/share/txr/stdlib/match.tl b/share/txr/stdlib/match.tl
index 0c672903..ec35e0a9 100644
--- a/share/txr/stdlib/match.tl
+++ b/share/txr/stdlib/match.tl
@@ -338,9 +338,10 @@
(result (gensym "result-"))
(clause-matches [mapcar (op compile-match (car @1) obj) clauses])
(clause-code (collect-each ((cl clauses)
- (cm clause-matches))
+ (cm clause-matches)
+ (i 0))
(mac-param-bind *match-form* (match . forms) cl
- ^(unless ,flag
+ ^(unless ,(unless (zerop i) flag)
(let (,*cm.(get-vars))
(set ,result ,cm.(wrap-guards
^(progn ,*cm.(assignments)