Intset-next micro-optimizations
authorAndy Wingo <wingo@pobox.com>
Tue, 31 Mar 2015 10:11:22 +0000 (12:11 +0200)
committerAndy Wingo <wingo@pobox.com>
Wed, 1 Apr 2015 08:53:23 +0000 (10:53 +0200)
* module/language/cps/intset.scm (intset-next): Micro-optimizations.

module/language/cps/intset.scm

index a6d3640..175b9e5 100644 (file)
   (define (visit-branch node shift i)
     (let lp ((i i) (idx (logand (ash i (- shift)) *branch-mask*)))
       (and (< idx *branch-size*)
-           (or (visit-node (vector-ref node idx) shift i)
+           (or (let ((node (vector-ref node idx)))
+                 (and node (visit-node node shift i)))
                (let ((inc (ash 1 shift)))
                  (lp (+ (round-down i shift) inc) (1+ idx)))))))
   (define (visit-node node shift i)
-    (and node
-         (if (= shift *leaf-bits*)
-             (visit-leaf node i)
-             (visit-branch node (- shift *branch-bits*) i))))
+    (if (= shift *leaf-bits*)
+        (visit-leaf node i)
+        (visit-branch node (- shift *branch-bits*) i)))
   (match bs
     (($ <intset> min shift root)
      (let ((i (if (and i (< min i))
                   (- i min)
                   0)))
-       (and (< i (ash 1 shift))
+       (and root (< i (ash 1 shift))
             (let ((i (visit-node root shift i)))
               (and i (+ min i))))))))