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:
+1
-1
@@ -3508,7 +3508,7 @@ mrb_encoding(mrb_state *mrb, mrb_value self)
|
||||
}
|
||||
|
||||
/* ---------------------------*/
|
||||
static mrb_mt_entry string_rom_entries[] = {
|
||||
static const mrb_mt_entry string_rom_entries[] = {
|
||||
MRB_MT_ENTRY(mrb_str_bytesize, MRB_SYM(bytesize), MRB_MT_FUNC|MRB_MT_NOARG),
|
||||
MRB_MT_ENTRY(mrb_str_cmp_m, MRB_OPSYM(cmp), MRB_MT_FUNC),
|
||||
MRB_MT_ENTRY(mrb_str_equal_m, MRB_OPSYM(eq), MRB_MT_FUNC),
|
||||
|
||||
Reference in New Issue
Block a user