use str_equal_p and blob_equal_p
This commit is contained in:
parent
d295653d20
commit
619fe8e15e
38
src/bool.c
38
src/bool.c
|
@ -10,14 +10,14 @@
|
|||
#include "picrin/blob.h"
|
||||
#include "picrin/string.h"
|
||||
|
||||
bool
|
||||
pic_string_equal_p(struct pic_string *str1, struct pic_string *str2)
|
||||
static bool
|
||||
str_equal_p(struct pic_string *str1, struct pic_string *str2)
|
||||
{
|
||||
return pic_strcmp(str1, str2) == 0;
|
||||
}
|
||||
|
||||
bool
|
||||
pic_blob_equal_p(struct pic_blob *blob1, struct pic_blob *blob2)
|
||||
static bool
|
||||
blob_equal_p(struct pic_blob *blob1, struct pic_blob *blob2)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
|
@ -32,7 +32,7 @@ pic_blob_equal_p(struct pic_blob *blob1, struct pic_blob *blob2)
|
|||
}
|
||||
|
||||
static bool
|
||||
pic_internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash *ht)
|
||||
internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash *ht)
|
||||
{
|
||||
pic_value local = pic_nil_value();
|
||||
size_t rapid_count = 0;
|
||||
|
@ -66,11 +66,17 @@ pic_internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xha
|
|||
return false;
|
||||
|
||||
switch (pic_type(x)) {
|
||||
case PIC_TT_STRING:
|
||||
return str_equal_p(pic_str_ptr(x), pic_str_ptr(y));
|
||||
|
||||
case PIC_TT_BLOB:
|
||||
return blob_equal_p(pic_blob_ptr(x), pic_blob_ptr(y));
|
||||
|
||||
case PIC_TT_PAIR:
|
||||
if (pic_nil_p(local)) {
|
||||
local = x;
|
||||
}
|
||||
if (pic_internal_equal_p(pic, pic_car(pic, x), pic_car(pic, y), depth + 1, ht)) {
|
||||
if (internal_equal_p(pic, pic_car(pic, x), pic_car(pic, y), depth + 1, ht)) {
|
||||
x = pic_cdr(pic, x);
|
||||
y = pic_cdr(pic, y);
|
||||
|
||||
|
@ -87,19 +93,6 @@ pic_internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xha
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
case PIC_TT_BLOB: {
|
||||
size_t i;
|
||||
struct pic_blob *u = pic_blob_ptr(x), *v = pic_blob_ptr(y);
|
||||
|
||||
if (u->len != v->len) {
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < u->len; ++i) {
|
||||
if (u->data[i] != v->data[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case PIC_TT_VECTOR: {
|
||||
size_t i;
|
||||
struct pic_vector *u, *v;
|
||||
|
@ -111,13 +104,11 @@ pic_internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xha
|
|||
return false;
|
||||
}
|
||||
for (i = 0; i < u->len; ++i) {
|
||||
if (! pic_internal_equal_p(pic, u->data[i], v->data[i], depth + 1, ht))
|
||||
if (! internal_equal_p(pic, u->data[i], v->data[i], depth + 1, ht))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case PIC_TT_STRING:
|
||||
return pic_strcmp(pic_str_ptr(x), pic_str_ptr(y)) == 0;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -128,7 +119,8 @@ pic_equal_p(pic_state *pic, pic_value x, pic_value y){
|
|||
xhash ht;
|
||||
|
||||
xh_init_ptr(&ht, 0);
|
||||
return pic_internal_equal_p(pic, x, y, 0, &ht);
|
||||
|
||||
return internal_equal_p(pic, x, y, 0, &ht);
|
||||
}
|
||||
|
||||
static pic_value
|
||||
|
|
Loading…
Reference in New Issue