class.c: merge conditional methods into ROM tables

Move conditional mrb_define_method_id() calls into ROM entry
arrays using #ifdef guards. With linear search, sizeof in
MRB_MT_ROM_TAB() adjusts automatically after preprocessing.

Cross-class ROM tables (methods a gem defines on a class it does
not own) are reverted to mrb_define_method_id(). Multiple gems
should not add ROM table layers to the same class; each layer
costs a 16-byte mrb_mt_tbl struct in RAM and deepens the lookup
chain. Use mrb_define_method_id() for cross-class methods.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-02-20 11:05:03 +09:00
parent 8adba34bd9
commit 20b9002214
15 changed files with 74 additions and 135 deletions
@@ -493,6 +493,7 @@ static const mrb_mt_entry integer_ext_rom_entries[] = {
};
static mrb_mt_tbl integer_ext_rom_mt = MRB_MT_ROM_TAB(integer_ext_rom_entries);
void
mrb_mruby_numeric_ext_gem_init(mrb_state* mrb)
{