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:
+3
-3
@@ -322,7 +322,7 @@ false_to_s(mrb_state *mrb, mrb_value obj)
|
||||
}
|
||||
|
||||
/* ---------------------------*/
|
||||
static mrb_mt_entry nil_rom_entries[] = {
|
||||
static const mrb_mt_entry nil_rom_entries[] = {
|
||||
MRB_MT_ENTRY(false_and, MRB_OPSYM(and), MRB_MT_FUNC),
|
||||
MRB_MT_ENTRY(false_or, MRB_OPSYM(or), MRB_MT_FUNC),
|
||||
MRB_MT_ENTRY(false_xor, MRB_OPSYM(xor), MRB_MT_FUNC),
|
||||
@@ -332,7 +332,7 @@ static mrb_mt_entry nil_rom_entries[] = {
|
||||
};
|
||||
static mrb_mt_tbl nil_rom_mt = MRB_MT_ROM_TAB(nil_rom_entries);
|
||||
|
||||
static mrb_mt_entry true_rom_entries[] = {
|
||||
static const mrb_mt_entry true_rom_entries[] = {
|
||||
MRB_MT_ENTRY(true_and, MRB_OPSYM(and), MRB_MT_FUNC),
|
||||
MRB_MT_ENTRY(true_or, MRB_OPSYM(or), MRB_MT_FUNC),
|
||||
MRB_MT_ENTRY(true_xor, MRB_OPSYM(xor), MRB_MT_FUNC),
|
||||
@@ -341,7 +341,7 @@ static mrb_mt_entry true_rom_entries[] = {
|
||||
};
|
||||
static mrb_mt_tbl true_rom_mt = MRB_MT_ROM_TAB(true_rom_entries);
|
||||
|
||||
static mrb_mt_entry false_rom_entries[] = {
|
||||
static const mrb_mt_entry false_rom_entries[] = {
|
||||
MRB_MT_ENTRY(false_and, MRB_OPSYM(and), MRB_MT_FUNC),
|
||||
MRB_MT_ENTRY(false_or, MRB_OPSYM(or), MRB_MT_FUNC),
|
||||
MRB_MT_ENTRY(false_xor, MRB_OPSYM(xor), MRB_MT_FUNC),
|
||||
|
||||
Reference in New Issue
Block a user