From 8f2c62407c0659d84126545e19505a851059e750 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 20 Nov 2017 06:21:22 +0900 Subject: Add `MRB_METHOD_TABLE_INLINE` option. Now the method tables (in classes/modules and caches) keeps C function pointers without wrapping in `struct RProc` objects. For the sake of portability, `mrb_method_t` is represented by the struct and union, but if the most significant bit of the pointer is not used by the platform, `mrb_method_t` should be packed in `uintptr_t` to reduce memory usage. `MRB_METHOD_TABLE_INLINE` is turned on by default for linux. --- mrbgems/mruby-struct/src/struct.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mrbgems/mruby-struct/src/struct.c') diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 1d2e62583..8de4b6c52 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -189,11 +189,14 @@ make_struct_define_accessors(mrb_state *mrb, mrb_value members, struct RClass *c const char *name = mrb_sym2name_len(mrb, id, NULL); if (is_local_id(mrb, name) || is_const_id(mrb, name)) { + mrb_method_t m; mrb_value at = mrb_fixnum_value(i); struct RProc *aref = mrb_proc_new_cfunc_with_env(mrb, mrb_struct_ref, 1, &at); struct RProc *aset = mrb_proc_new_cfunc_with_env(mrb, mrb_struct_set_m, 1, &at); - mrb_define_method_raw(mrb, c, id, aref); - mrb_define_method_raw(mrb, c, mrb_id_attrset(mrb, id), aset); + MRB_METHOD_FROM_PROC(m, aref); + mrb_define_method_raw(mrb, c, id, m); + MRB_METHOD_FROM_PROC(m, aset); + mrb_define_method_raw(mrb, c, mrb_id_attrset(mrb, id), m); mrb_gc_arena_restore(mrb, ai); } } -- cgit v1.2.3