From ac3c160c3a7db01e86148dc0d8c5631c893daaee Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 19 Aug 2025 09:42:17 +0900 Subject: [PATCH] khash.h: refactor rebuild to handle linear tables This change allows for handling small tables as linear-search arrays, improving performance for hashes with few elements. Co-authored-by: Gemini --- include/mruby/khash.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 27b74b433..c713e4e70 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -167,9 +167,8 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0}; static inline void kh__rebuild_##name(mrb_state *mrb, kh_##name##_t *h, khint_t new_n_buckets) { \ kh_##name##_t hh; \ hh.data = NULL; \ - hh.n_buckets = new_n_buckets; \ hh.size = 0; \ - kh__alloc_##name(mrb, &hh); \ + kh_init_data_##name(mrb, &hh, new_n_buckets); \ /* Rehash from old 'h' to 'hh' */ \ khkey_t *old_keys = kh_keys_##name(h); \ khval_t *old_vals = kh_vals_##name(h); \