Commits

evhan committed a0d7f35

add start index to bv->int, avoids unnecessary calls to bv-copy

Comments (0)

Files changed (1)

 (define bytevector->integer
   (case-lambda
     ((v)
-     (bytevector->integer v (bytevector-length v)))
-    ((v l)
-     (do ((i 0 (+ i 1))
-          (a 0 (+ a (« (bytevector-u8-ref v i) (* i 8)))))
-         ((= i l) a)))))
+     (bytevector->integer v 0 (bytevector-length v)))
+    ((v e)
+     (bytevector->integer v 0 e))
+    ((v s e)
+     (do ((s s (+ s 1))
+          (i 0 (+ i 1))
+          (a 0 (+ a (« (bytevector-u8-ref v s) (* i 8)))))
+         ((= s e) a)))))
 
 (define (->bytevector o)
   (cond ((bytevector? o) o)
     (lambda (c d)
       (define (siphash-c-d k)
         (assert (= (bytevector-length k) 16) "key must be 16 bytes")
-        (let* ((k0 (bytevector->integer (bytevector-copy k 0 8) 8))
-               (k1 (bytevector->integer (bytevector-copy k 8 16) 8))
+        (let* ((k0 (bytevector->integer k 0 8))
+               (k1 (bytevector->integer k 8 16))
                (v0 (⊕ k0 m0))
                (v1 (⊕ k1 m1))
                (v2 (⊕ k0 m2))
                     ((> i (- l 8))
                      (process-message!
                       (❘ (« (modulo l 256) 56)
-                         (bytevector->integer (bytevector-copy m i l)))))
+                         (bytevector->integer m i l))))
                   (process-message!
-                   (bytevector->integer (bytevector-copy m i (+ i 8)) 8)))
+                   (bytevector->integer m i (+ i 8))))
                 (set! v2 (⊕ v2 255))
                 (do-times d
                   (sip-round! v0 v1 v2 v3))