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. --- include/mruby.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'include/mruby.h') diff --git a/include/mruby.h b/include/mruby.h index 1413d604e..5c8d38200 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -170,11 +170,25 @@ struct mrb_context { # define MRB_METHOD_CACHE_SIZE (1<<7) #endif +typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value); + +#ifdef MRB_METHOD_TABLE_INLINE +typedef uintptr_t mrb_method_t; +#else +typedef struct { + mrb_bool func_p; + union { + struct RProc *proc; + mrb_func_t func; + }; +} mrb_method_t; +#endif + #ifdef MRB_METHOD_CACHE struct mrb_cache_entry { struct RClass *c; mrb_sym mid; - struct RProc *m; + mrb_method_t m; }; #endif @@ -257,9 +271,6 @@ typedef struct mrb_state { mrb_int atexit_stack_len; } mrb_state; - -typedef mrb_value (*mrb_func_t)(mrb_state *mrb, mrb_value); - /** * Defines a new class. * -- cgit v1.2.3