Compare commits

...

4 Commits

Author SHA1 Message Date
Sofia Rodrigues
3609d2e321 fix: change 0 and 1 to false and true 2025-07-25 14:32:54 -03:00
Sofia Rodrigues
4ff5e275ef feat: add same obj comparison 2025-07-25 13:40:48 -03:00
Sofia Rodrigues
24f2699e78 revert: change 2025-07-07 18:26:04 -03:00
Sofia Rodrigues
689bd4ffde feat: migrate beq for improved perf using memcmp 2025-07-01 23:23:19 -03:00
2 changed files with 25 additions and 2 deletions

View File

@@ -23,10 +23,18 @@ attribute [extern "lean_byte_array_data"] ByteArray.data
namespace ByteArray
deriving instance BEq for ByteArray
attribute [ext] ByteArray
/--
Checks whether two `ByteArray` instances have the same length and identical content. Normally used
via the `==` operator.
-/
@[extern "lean_byte_array_beq"]
protected def beq (a b : @& ByteArray) : Bool :=
BEq.beq a.data b.data
instance : BEq ByteArray := ByteArray.beq
instance : DecidableEq ByteArray :=
fun _ _ => decidable_of_decidable_of_iff ByteArray.ext_iff.symm

View File

@@ -2419,6 +2419,21 @@ extern "C" LEAN_EXPORT obj_res lean_byte_array_mk(obj_arg a) {
return r;
}
extern "C" LEAN_EXPORT bool lean_byte_array_beq(obj_arg a, obj_arg b) {
if (a == b) {
return true;
}
size_t size_a = lean_sarray_size(a);
size_t size_b = lean_sarray_size(b);
if (size_a != size_b) {
return false;
}
return memcmp(lean_sarray_cptr(a), lean_sarray_cptr(b), size_a) == 0;
}
extern "C" LEAN_EXPORT obj_res lean_byte_array_data(obj_arg a) {
usize sz = lean_sarray_size(a);
obj_res r = lean_alloc_array(sz, sz);