From: Igor Putovny Date: Wed, 11 Jun 2025 15:44:38 +0000 (+0200) Subject: Assert that hash table is not being modified during HASH_WALK X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fip-assert-hash-walk;p=thirdparty%2Fbird.git Assert that hash table is not being modified during HASH_WALK According to measurements of hash_test, hash table with this assertion added was not found to be significantly slower than without it on average. Therefore we conclude that this addition would not hamper the performance of HASH_WALK. --- diff --git a/lib/hash.h b/lib/hash.h index 3c173958f..4c05c6d7e 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -165,10 +165,11 @@ #define HASH_WALK(v,next,n) \ do { \ HASH_TYPE(v) *n; \ + const uint _count = v.count; \ uint _i; \ uint _s = HASH_SIZE(v); \ for (_i = 0; _i < _s; _i++) \ - for (n = (v).data[_i]; n; n = n->next) + for (n = (v).data[_i]; ({ ASSERT_DIE(v.count == _count); }), n; n = n->next) #define HASH_WALK_END } while (0)