mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
class.c, string.c: ROM method table for String class
Move String's 46 method definitions from runtime mrb_define_method_id() calls to a static ROM method table sorted at init time. mrb_mt_init_rom() sorts the parallel vals/keys arrays by presym ID and sets the readonly flag. Expose mt_tbl and related types in internal.h so ROM tables can be defined in individual source files. When MRB_NO_PRESYM is defined, falls back to traditional runtime method registration. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,29 @@ mrb_value mrb_mod_const_missing(mrb_state *mrb, mrb_value mod);
|
||||
mrb_value mrb_const_missing(mrb_state *mrb, mrb_value mod, mrb_sym sym);
|
||||
size_t mrb_class_mt_memsize(mrb_state*, struct RClass*);
|
||||
mrb_value mrb_obj_extend(mrb_state*, mrb_value obj);
|
||||
|
||||
/* ROM method table types for static method registration */
|
||||
union mt_ptr {
|
||||
const struct RProc *proc;
|
||||
mrb_func_t func;
|
||||
};
|
||||
|
||||
typedef struct mt_tbl {
|
||||
int size;
|
||||
int alloc; /* bit 30: MT_READONLY_BIT */
|
||||
union mt_ptr *ptr;
|
||||
struct mt_tbl *next;
|
||||
} mt_tbl;
|
||||
|
||||
#define MT_READONLY_BIT (1 << 30)
|
||||
#define MT_KEY_SHIFT 4
|
||||
#define MT_KEY(sym, flags) ((sym)<<MT_KEY_SHIFT|(flags))
|
||||
#define MT_FUNC 8 /* MRB_METHOD_FUNC_FL */
|
||||
#define MT_NOARG 4 /* MRB_METHOD_NOARG_FL */
|
||||
#define MT_PUBLIC 0 /* MRB_METHOD_PUBLIC_FL */
|
||||
#define MT_PRIVATE 1 /* MRB_METHOD_PRIVATE_FL */
|
||||
|
||||
void mrb_mt_init_rom(struct RClass *c, mt_tbl *rom);
|
||||
#endif
|
||||
|
||||
mrb_value mrb_obj_equal_m(mrb_state *mrb, mrb_value);
|
||||
|
||||
Reference in New Issue
Block a user