restoring hashing of trailing data for uvectors

This commit is contained in:
Alex Shinn 2020-08-04 18:31:20 +09:00
parent b4520b31f5
commit 449312d3bd

View file

@ -48,10 +48,10 @@ sexp sexp_string_ci_hash (sexp ctx, sexp self, sexp_sint_t n, sexp str, sexp bou
}
static sexp_uint_t hash_one (sexp ctx, sexp obj, sexp_uint_t bound, sexp_sint_t depth) {
sexp_uint_t acc = FNV_OFFSET_BASIS;
sexp_uint_t acc = FNV_OFFSET_BASIS, right_size;
sexp_sint_t i, len;
sexp t, *p;
char *p0;
char *p0, *p_right;
loop:
if (obj) {
#if SEXP_USE_FLONUMS
@ -64,8 +64,15 @@ static sexp_uint_t hash_one (sexp ctx, sexp obj, sexp_uint_t bound, sexp_sint_t
t = sexp_object_type(ctx, obj);
p = (sexp*) (((char*)obj) + sexp_type_field_base(t));
p0 = ((char*)obj) + offsetof(struct sexp_struct, value);
/* if the field_base is 0, skip to the value */
if ((sexp)p == obj) p=(sexp*)p0;
/* hash only eq-object slots */
/* hash uvector data (otherwise strings all hash to the same value) */
if (sexp_bytesp(obj) || sexp_uvectorp(obj)) {
p_right = ((char*)p + sexp_type_num_slots_of_object(t, obj)*sizeof(sexp));
right_size = ((char*)obj + sexp_type_size_of_object(t, obj)) - p_right;
for (i=0; i<right_size; i++) {acc *= FNV_PRIME; acc ^= p_right[i];}
}
/* hash eq-object slots */
len = sexp_type_num_eq_slots_of_object(t, obj);
if (len > 0) {
depth--;