Peephole optimization for iterating over an empty set (no allocation).
This commit is contained in:
parent
4721a79c8f
commit
a193cd9efb
|
@ -309,6 +309,8 @@
|
||||||
(lambda () #'in-set)
|
(lambda () #'in-set)
|
||||||
(lambda (stx)
|
(lambda (stx)
|
||||||
(syntax-case stx (set)
|
(syntax-case stx (set)
|
||||||
|
;; Set construction is costly, so specialize empty/singleton cases
|
||||||
|
[[(id) (_ (set))] #'[(id) (:do-in ([(id) #f]) #t () #f () #f #f ())]]
|
||||||
[[(id) (_ (set expr))] #'[(id) (:do-in ([(id) expr]) #t () #t () #t #f ())]]
|
[[(id) (_ (set expr))] #'[(id) (:do-in ([(id) expr]) #t () #t () #t #f ())]]
|
||||||
[[(id) (_ st)]
|
[[(id) (_ st)]
|
||||||
#`[(id)
|
#`[(id)
|
||||||
|
|
|
@ -105,7 +105,11 @@
|
||||||
(test '(1 2 3) sort (for/list ([v s]) v) <)
|
(test '(1 2 3) sort (for/list ([v s]) v) <)
|
||||||
(test '(1 2 3) sort (for/list ([v (in-set s)]) v) <)
|
(test '(1 2 3) sort (for/list ([v (in-set s)]) v) <)
|
||||||
(test '(1 2 3) sort (let ([seq (in-set s)]) (for/list ([v seq]) v)) <)
|
(test '(1 2 3) sort (let ([seq (in-set s)]) (for/list ([v seq]) v)) <)
|
||||||
|
;; Optimized
|
||||||
(test '(1) sort (for/list ([v (in-set (set 1))]) v) <)
|
(test '(1) sort (for/list ([v (in-set (set 1))]) v) <)
|
||||||
|
(test #t values (let ([noset #t])
|
||||||
|
(for ([v (in-set (set))]) (set! noset #f))
|
||||||
|
noset))
|
||||||
|
|
||||||
|
|
||||||
(void))
|
(void))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user