From d5c93fc724fb5d58b565f90e79c43c108530a9b7 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 23 Dec 2025 08:32:23 +0900 Subject: [PATCH] class.c, variable.c: rename bsearch_idx to avoid name collision Rename static bsearch_idx functions to disambiguate: - class.c: mt_bsearch_idx (method table) - variable.c: iv_bsearch_idx (instance variable table) This prepares for future amalgamation support. Co-authored-by: Claude --- src/class.c | 8 ++++---- src/variable.c | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/class.c b/src/class.c index 2e1a053b4..1aca0de58 100644 --- a/src/class.c +++ b/src/class.c @@ -98,7 +98,7 @@ mt_new(mrb_state *mrb) /* Branch-free binary search helper for method table keys */ static inline int -bsearch_idx(mrb_sym *keys, int size, mrb_sym target) +mt_bsearch_idx(mrb_sym *keys, int size, mrb_sym target) { if (size == 0) return 0; int n = size; @@ -143,7 +143,7 @@ mt_put(mrb_state *mrb, mt_tbl *t, mrb_sym sym, mrb_sym flags, union mt_ptr ptrva * If table is empty, insertion index is 0. * Otherwise, find the insertion/update position branch-free. */ - int lo = bsearch_idx(keys, t->size, sym); + int lo = mt_bsearch_idx(keys, t->size, sym); /* If the key already exists, update its value and return */ if (lo < t->size && MT_KEY_SYM(keys[lo]) == sym) { @@ -176,7 +176,7 @@ mt_get(mrb_state *mrb, mt_tbl *t, mrb_sym sym, union mt_ptr *pp) union mt_ptr *vals = mt_vals(t); /* Find the position in a branch-free manner */ - int lo = bsearch_idx(keys, t->size, sym); + int lo = mt_bsearch_idx(keys, t->size, sym); /* If found, set *pp to the value and return the full key */ if (lo < t->size && MT_KEY_SYM(keys[lo]) == sym) { @@ -199,7 +199,7 @@ mt_del(mrb_state *mrb, mt_tbl *t, mrb_sym sym) union mt_ptr *vals = mt_vals(t); /* Find the index of `sym` in a branch-free manner */ - int lo = bsearch_idx(keys, t->size, sym); + int lo = mt_bsearch_idx(keys, t->size, sym); /* If the key exists at index lo, remove it by shifting left */ if (lo < t->size && MT_KEY_SYM(keys[lo]) == sym) { diff --git a/src/variable.c b/src/variable.c index 90557fdd4..f697cd445 100644 --- a/src/variable.c +++ b/src/variable.c @@ -69,7 +69,7 @@ iv_rehash(mrb_state *mrb, iv_tbl *t) /* Branch-free binary search helper: returns the index where `target` should be inserted/found. */ static inline int -bsearch_idx(mrb_sym *keys, int size, mrb_sym target) { +iv_bsearch_idx(mrb_sym *keys, int size, mrb_sym target) { if (size == 0) return 0; int n = size; mrb_sym *p = keys; @@ -107,7 +107,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val) /* Determine insertion/update index: * If table has entries, use branch-free search; otherwise index = 0. */ - int lo = bsearch_idx(keys, t->size, sym); + int lo = iv_bsearch_idx(keys, t->size, sym); /* If the key already exists, update its value and return */ if (lo < t->size && keys[lo] == sym) { @@ -120,7 +120,7 @@ iv_put(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value val) iv_rehash(mrb, t); keys = (mrb_sym*)&t->ptr[t->alloc]; vals = t->ptr; - lo = bsearch_idx(keys, t->size, sym); + lo = iv_bsearch_idx(keys, t->size, sym); } /* Shift existing entries right to make room at index lo */ @@ -147,7 +147,7 @@ iv_get(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp) mrb_value *vals = t->ptr; /* Find index in a branch-free manner */ - int lo = bsearch_idx(keys, t->size, sym); + int lo = iv_bsearch_idx(keys, t->size, sym); /* If found, store value (if vp provided) and return 1-based position */ if (lo < t->size && keys[lo] == sym) { @@ -170,7 +170,7 @@ iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp) mrb_value *vals = t->ptr; /* Find index in a branch-free manner */ - int lo = bsearch_idx(keys, t->size, sym); + int lo = iv_bsearch_idx(keys, t->size, sym); /* If found, optionally return value and shift entries left to delete */ if (lo < t->size && keys[lo] == sym) {