mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
class.c: use linear search for method tables; make ROM entries const
Replace binary search with linear scan in mt_get(), mt_put(), mt_del(), mt_chain_has(), and mrb_mt_foreach(). The method cache makes repeated lookups O(1), so linear scan on cache misses is acceptable. This removes the sorting requirement, allowing ROM entry arrays to be declared const. On embedded systems, const static data resides in flash/ROM instead of RAM, saving ~8.4KB for ~700 method entries on 32-bit MCUs. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2219,7 +2219,7 @@ str_prepend(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
|
||||
/* ---------------------------*/
|
||||
static mrb_mt_entry string_ext_rom_entries[] = {
|
||||
static const mrb_mt_entry string_ext_rom_entries[] = {
|
||||
MRB_MT_ENTRY(mrb_str_dump, MRB_SYM(dump), MRB_MT_FUNC|MRB_MT_NOARG),
|
||||
MRB_MT_ENTRY(str_swapcase_bang, MRB_SYM_B(swapcase), MRB_MT_FUNC|MRB_MT_NOARG),
|
||||
MRB_MT_ENTRY(mrb_str_slice_bang, MRB_SYM_B(slice), MRB_MT_FUNC),
|
||||
@@ -2276,7 +2276,7 @@ static mrb_mt_entry string_ext_rom_entries[] = {
|
||||
};
|
||||
static mrb_mt_tbl string_ext_rom_mt = MRB_MT_ROM_TAB(string_ext_rom_entries);
|
||||
|
||||
static mrb_mt_entry integer_chr_rom_entries[] = {
|
||||
static const mrb_mt_entry integer_chr_rom_entries[] = {
|
||||
MRB_MT_ENTRY(int_chr, MRB_SYM(chr), MRB_MT_FUNC),
|
||||
};
|
||||
static mrb_mt_tbl integer_chr_rom_mt = MRB_MT_ROM_TAB(integer_chr_rom_entries);
|
||||
|
||||
Reference in New Issue
Block a user