mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Add a fast-path for mrb_type
By adding a fast-path where we ignore boxed types we can gain a pretty substantial speedup of mrb_iv_get, making it about 25% faster during a standard optcarrot benchmark run. NOTE: It is just mrb_iv_get that is that much faster, the whole benchmark seems to be about 3-5% faster with word boxing.
This commit is contained in:
@@ -98,6 +98,16 @@ mrb_type(mrb_value o)
|
||||
}
|
||||
}
|
||||
|
||||
MRB_INLINE enum mrb_vtype
|
||||
mrb_unboxed_type(mrb_value o)
|
||||
{
|
||||
if (!mrb_float_p(o) && mrb_nb_tt(o) == MRB_NANBOX_TT_OBJECT && o.u != 0) {
|
||||
return ((struct RBasic*)(uintptr_t)o.u)->tt;
|
||||
} else {
|
||||
return MRB_TT_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
#define NANBOX_SET_MISC_VALUE(r,t,i) NANBOX_SET_VALUE(r, MRB_NANBOX_TT_MISC, ((uint64_t)(t)<<32) | (i))
|
||||
|
||||
#define mrb_float(o) mrb_nan_boxing_value_float(o)
|
||||
|
||||
@@ -26,15 +26,16 @@ typedef struct mrb_value {
|
||||
enum mrb_vtype tt;
|
||||
} mrb_value;
|
||||
|
||||
#define mrb_ptr(o) (o).value.p
|
||||
#define mrb_cptr(o) mrb_ptr(o)
|
||||
#define mrb_ptr(o) (o).value.p
|
||||
#define mrb_cptr(o) mrb_ptr(o)
|
||||
#ifndef MRB_NO_FLOAT
|
||||
#define mrb_float(o) (o).value.f
|
||||
#define mrb_float(o) (o).value.f
|
||||
#endif
|
||||
#define mrb_fixnum(o) (o).value.i
|
||||
#define mrb_integer(o) mrb_fixnum(o)
|
||||
#define mrb_symbol(o) (o).value.sym
|
||||
#define mrb_type(o) (o).tt
|
||||
#define mrb_fixnum(o) (o).value.i
|
||||
#define mrb_integer(o) mrb_fixnum(o)
|
||||
#define mrb_symbol(o) (o).value.sym
|
||||
#define mrb_type(o) (o).tt
|
||||
#define mrb_unboxed_type(o) (o).tt
|
||||
|
||||
#define BOXNIX_SET_VALUE(o, ttt, attr, v) do {\
|
||||
(o).tt = ttt;\
|
||||
|
||||
@@ -228,4 +228,17 @@ mrb_type(mrb_value o)
|
||||
mrb_val_union(o).bp->tt;
|
||||
}
|
||||
|
||||
MRB_INLINE enum mrb_vtype
|
||||
mrb_unboxed_type(mrb_value o)
|
||||
{
|
||||
if (mrb_nil_p(o)) {
|
||||
return MRB_TT_FALSE;
|
||||
} else if ((o.w & WORDBOX_IMMEDIATE_MASK) == 0) {
|
||||
return mrb_val_union(o).bp->tt;
|
||||
} else {
|
||||
return MRB_TT_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* MRUBY_BOXING_WORD_H */
|
||||
|
||||
+1
-1
@@ -282,7 +282,7 @@ mrb_vm_special_set(mrb_state *mrb, mrb_sym i, mrb_value v)
|
||||
static mrb_bool
|
||||
obj_iv_p(mrb_value obj)
|
||||
{
|
||||
switch (mrb_type(obj)) {
|
||||
switch (mrb_unboxed_type(obj)) {
|
||||
case MRB_TT_OBJECT:
|
||||
case MRB_TT_CLASS:
|
||||
case MRB_TT_MODULE:
|
||||
|
||||
Reference in New Issue
Block a user