From 657ece4d8bac9cd77bf85d45505346379218afce Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Fri, 6 Jan 2017 19:57:00 -0800 Subject: [PATCH] =?utf8?q?Implement=20bytevector=3D=3F=20and=20add=20bytev?= =?utf8?q?ector=20support=20to=20equal=3F.?= --- src/runtime/bytevector.scm | 9 +++++++++ src/runtime/equals.scm | 2 ++ src/runtime/runtime.pkg | 1 + 3 files changed, 12 insertions(+) diff --git a/src/runtime/bytevector.scm b/src/runtime/bytevector.scm index b39b258a8..f01d322a5 100644 --- a/src/runtime/bytevector.scm +++ b/src/runtime/bytevector.scm @@ -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)))))))) (define (string->utf8 string #!optional start end) (guarantee string? string 'string->utf8) diff --git a/src/runtime/equals.scm b/src/runtime/equals.scm index d2eae6721..8c5147b28 100644 --- a/src/runtime/equals.scm +++ b/src/runtime/equals.scm @@ -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) diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index e5b75c3af..c106c2a86 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -1128,6 +1128,7 @@ USA. bytevector-length bytevector-u8-ref bytevector-u8-set! + bytevector=? bytevector? make-bytevector string->utf8 -- 2.25.1