From 71c5e2c53686cb01173b81a41eced59a2eabf8d0 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 2 Aug 2025 21:35:45 +0900 Subject: [PATCH] khash: move internal helpers from KHASH_DECLARE to KHASH_DEFINE Moved kh_data_size_##name() and kh_flags_##name() from KHASH_DECLARE to KHASH_DEFINE section where internal implementation details belong. This improves the separation of concerns: - KHASH_DECLARE: public API only (struct definition, function declarations) - KHASH_DEFINE: implementation details and internal helper functions No functional changes, only better code organization. Co-authored-by: Claude --- include/mruby/khash.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/mruby/khash.h b/include/mruby/khash.h index b3dd26573..eb7ed2511 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -78,11 +78,6 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0}; khint_t n_buckets; /* Number of buckets (power of 2) */ \ khint_t size; /* Number of elements */ \ } kh_##name##_t; \ - /* Size calculation helper */ \ - static inline size_t kh_data_size_##name(khint_t count) { \ - return sizeof(khkey_t) * count + \ - (kh_is_map ? sizeof(khval_t) * count : 0); \ - } \ /* Address calculation functions for optimized memory layout */ \ static inline khkey_t* kh_keys_##name(const kh_##name##_t *h) { \ return (khkey_t*)(h)->data; \ @@ -91,9 +86,6 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0}; return kh_is_map ? \ (khval_t*)((uint8_t*)(h)->data + sizeof(khkey_t) * (h)->n_buckets) : NULL; \ } \ - static inline uint8_t* kh_flags_##name(const kh_##name##_t *h) { \ - return (uint8_t*)(h)->data + kh_data_size_##name((h)->n_buckets); \ - } \ void kh_alloc_##name(mrb_state *mrb, kh_##name##_t *h); \ kh_##name##_t *kh_init_##name##_size(mrb_state *mrb, khint_t size); \ kh_##name##_t *kh_init_##name(mrb_state *mrb); \ @@ -119,6 +111,14 @@ static const uint8_t __m_either[] = {0x03, 0x0c, 0x30, 0xc0}; */ #define KHASH_DEFINE(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ mrb_noreturn void mrb_raise_nomemory(mrb_state *mrb); \ + /* Internal helper functions */ \ + static inline size_t kh_data_size_##name(khint_t count) { \ + return sizeof(khkey_t) * count + \ + (kh_is_map ? sizeof(khval_t) * count : 0); \ + } \ + static inline uint8_t* kh_flags_##name(const kh_##name##_t *h) { \ + return (uint8_t*)(h)->data + kh_data_size_##name((h)->n_buckets); \ + } \ /* Small table optimization functions */ \ static inline int kh_is_small_##name(const kh_##name##_t *h) { \ return h->n_buckets == 0; /* Small table marker */ \