Implement bytevector=? and add bytevector support to equal?.
authorChris Hanson <org/chris-hanson/cph>
Sat, 7 Jan 2017 03:57:00 +0000 (19:57 -0800)
committerChris Hanson <org/chris-hanson/cph>
Sat, 7 Jan 2017 03:57:00 +0000 (19:57 -0800)
src/runtime/bytevector.scm
src/runtime/equals.scm
src/runtime/runtime.pkg

index b39b258a8dda2e25b53b092cecd04c77f6190cc2..f01d322a51490d6c3cb21e632dd6b0c9b5601f30 100644 (file)
@@ -85,6 +85,15 @@ USA.
    from
    (if (default-object? start) 0 start)
    (if (default-object? end) (bytevector-length from) end)))
+
+(define (bytevector=? b1 b2)
+  (let ((length (bytevector-length b1)))
+    (and (fix:= length (bytevector-length b2))
+        (let loop ((index 0))
+          (or (not (fix:< index length))
+              (and (fix:= (bytevector-u8-ref b1 index)
+                          (bytevector-u8-ref b2 index))
+                   (loop (fix:+ index 1))))))))
 \f
 (define (string->utf8 string #!optional start end)
   (guarantee string? string 'string->utf8)
index d2eae67217ea4f1590a1afb97dfee6655d2492bd..8c5147b281a17e73ca38a8317f67effb2dc32ba3 100644 (file)
@@ -59,6 +59,8 @@ USA.
                              (and (equal? (vector-ref x index)
                                           (vector-ref y index))
                                   (loop (fix:+ index 1))))))))
+               ((bytevector? y)
+                (bytevector=? x y))
                ((string? y)
                 (string=? x y))
                ((number? y)
index e5b75c3af235f979e641b86ff8225f2d0dd07d71..c106c2a8644016d28f8ae72f3570be6d89593cc8 100644 (file)
@@ -1128,6 +1128,7 @@ USA.
          bytevector-length
          bytevector-u8-ref
          bytevector-u8-set!
+         bytevector=?
          bytevector?
          make-bytevector
          string->utf8