diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-20 06:21:22 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-20 18:33:41 +0900 |
| commit | 8f2c62407c0659d84126545e19505a851059e750 (patch) | |
| tree | 7a073d389fc2f5fc7c14f86ffa96d0145bff9f82 /include/mruby.h | |
| parent | 6c06e77446f3cca4a92b3df8d0a5fe568c5fdc65 (diff) | |
| download | mruby-8f2c62407c0659d84126545e19505a851059e750.tar.gz mruby-8f2c62407c0659d84126545e19505a851059e750.zip | |
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.
Diffstat (limited to 'include/mruby.h')
| -rw-r--r-- | include/mruby.h | 19 |
1 files changed, 15 insertions, 4 deletions
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. * |
