mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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 <noreply@anthropic.com>
This commit is contained in:
+4
-4
@@ -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) {
|
||||
|
||||
+5
-5
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user