From da09bae640ad288bb4c8463910605cbefc718143 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 3 Aug 2025 06:32:35 +0900 Subject: [PATCH] khash.h: inline kh_alloc_small function used only once Removed kh_alloc_small_##name() function and inlined its body into the single call site in kh_init_data_##name(). This eliminates unnecessary function call overhead and reduces code complexity. The function was only 2 lines and called once, making it an ideal candidate for inlining. Co-authored-by: Claude --- include/mruby/khash.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 03a38cdf2..2e49f026c 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -181,10 +181,6 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0}; if (ret) *ret = 1; /* New key */ \ return h->size - 1; \ } \ - static inline void kh_alloc_small_##name(mrb_state *mrb, kh_##name##_t *h) { \ - h->data = mrb_malloc(mrb, kh_kv_size_##name(KHASH_SMALL_THRESHOLD));\ - h->size = 0; \ - } \ void kh_alloc_##name(mrb_state *mrb, kh_##name##_t *h) \ { \ khint_t sz = h->n_buckets; \ @@ -337,9 +333,8 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0}; if (size <= KHASH_SMALL_THRESHOLD) { \ /* Start as small table */ \ h->n_buckets = 0; /* Small table marker */ \ - if (kh_alloc_small_##name(mrb, h)) { \ - mrb_raise_nomemory(mrb); \ - } \ + h->data = mrb_malloc(mrb, kh_kv_size_##name(KHASH_SMALL_THRESHOLD)); \ + h->size = 0; \ } \ else { \ /* Start as regular hash table */ \