From 2154663a0a553385171c08674a009c6f64e62cd5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 18 Oct 2019 18:56:20 -0700 Subject: hash: observe count limit for vectors and hash tables. * hash.c (equal_hash): Break out of hashing a vector when the count is exceeded. (hash_hash_op): Likewise for traversing a hash table. --- hash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hash.c b/hash.c index 22532e5b..529202e4 100644 --- a/hash.c +++ b/hash.c @@ -239,6 +239,8 @@ ucnum equal_hash(val obj, int *count, ucnum seed) for (i = 0, lseed = seed; i < len; i++, lseed += seed) { h *= 2; h += equal_hash(obj->v.vec[i], count, lseed); + if ((*count)-- <= 0) + break; } return h; @@ -474,7 +476,7 @@ static ucnum hash_hash_op(val obj, int *count, ucnum seed) iter = hash_begin(obj); - while ((cell = hash_next(iter)) != nil) { + while ((*count)-- > 0 && (cell = hash_next(iter)) != nil) { out += equal_hash(cell, count, seed); out &= NUM_MAX; } -- cgit v1.2.3