From 2ce541ed4beb012eb0bcd6fd719c13cb8ed283bb Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 24 Jan 2017 20:54:29 -0500 Subject: [PATCH] Issue #155 - Check bytevectors for deep equality --- CHANGELOG.md | 1 + runtime.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5f8afc..fbe98b68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Features Bug Fixes +- Thanks to Koz Ross, `equal?` has been updated to check bytevectors for deep equality. - Display characters such as `#\space` correctly when output via `write`. - Thanks for Seth Alves, removed unnecessary include of `ck_string.h` which is not provided in older versions of `libck`. diff --git a/runtime.c b/runtime.c index 3f6d6421..76e6f8bd 100644 --- a/runtime.c +++ b/runtime.c @@ -588,6 +588,19 @@ int equal(object x, object y) return 1; } return 0; + case bytevector_tag: + if (is_object_type(y) && + type_of(y) == bytevector_tag && + ((bytevector) x)->len == ((bytevector) y)->len) { + int i; + for (i = 0; i < ((bytevector) x)->len; i++) { + if (((bytevector)x)->data[i] != ((bytevector)y)->data[i]) { + return 0; + } + } + return 1; + } + return 0; default: return x == y; }