Feature #15902 ยป 0001-Add-a-specialized-instruction-for-.nil-calls.patch
| benchmark/nil_p.yml | ||
|---|---|---|
|
prelude: |
|
||
|
class Niller; def nil?; true; end; end
|
||
|
xnil, notnil = nil, Object.new
|
||
|
niller = Niller.new
|
||
|
benchmark:
|
||
|
- xnil.nil?
|
||
|
- notnil.nil?
|
||
|
- niller.nil?
|
||
|
loop_count: 10000000
|
||
| compile.c | ||
|---|---|---|
|
case idLength: SP_INSN(length); return COMPILE_OK;
|
||
|
case idSize: SP_INSN(size); return COMPILE_OK;
|
||
|
case idEmptyP: SP_INSN(empty_p);return COMPILE_OK;
|
||
|
case idNilP: SP_INSN(nil_p); return COMPILE_OK;
|
||
|
case idSucc: SP_INSN(succ); return COMPILE_OK;
|
||
|
case idNot: SP_INSN(not); return COMPILE_OK;
|
||
|
}
|
||
| defs/id.def | ||
|---|---|---|
|
max
|
||
|
min
|
||
|
freeze
|
||
|
nil?
|
||
|
inspect
|
||
|
intern
|
||
|
object_id
|
||
| insns.def | ||
|---|---|---|
|
}
|
||
|
}
|
||
|
/* optimized nil? */
|
||
|
DEFINE_INSN
|
||
|
opt_nil_p
|
||
|
(CALL_INFO ci, CALL_CACHE cc)
|
||
|
(VALUE recv)
|
||
|
(VALUE val)
|
||
|
{
|
||
|
val = vm_opt_nil_p(ci, cc, recv);
|
||
|
if (val == Qundef) {
|
||
|
CALL_SIMPLE_METHOD();
|
||
|
}
|
||
|
}
|
||
|
DEFINE_INSN
|
||
|
opt_str_uminus
|
||
|
(VALUE str, CALL_INFO ci, CALL_CACHE cc)
|
||
| object.c | ||
|---|---|---|
|
*/
|
||
|
static VALUE
|
||
|
VALUE
|
||
|
rb_false(VALUE obj)
|
||
|
{
|
||
|
return Qfalse;
|
||
| vm.c | ||
|---|---|---|
|
OP(Call, CALL), (C(Proc));
|
||
|
OP(And, AND), (C(Integer));
|
||
|
OP(Or, OR), (C(Integer));
|
||
|
OP(NilP, NIL_P), (C(NilClass));
|
||
|
#undef C
|
||
|
#undef OP
|
||
|
}
|
||
| vm_core.h | ||
|---|---|---|
|
BOP_LENGTH,
|
||
|
BOP_SIZE,
|
||
|
BOP_EMPTY_P,
|
||
|
BOP_NIL_P,
|
||
|
BOP_SUCC,
|
||
|
BOP_GT,
|
||
|
BOP_GE,
|
||
| vm_insnhelper.c | ||
|---|---|---|
|
}
|
||
|
}
|
||
|
VALUE rb_false(VALUE obj);
|
||
|
static VALUE
|
||
|
vm_opt_nil_p(CALL_INFO ci, CALL_CACHE cc, VALUE recv)
|
||
|
{
|
||
|
if (recv == Qnil) {
|
||
|
if (BASIC_OP_UNREDEFINED_P(BOP_NIL_P, NIL_REDEFINED_OP_FLAG)) {
|
||
|
return Qtrue;
|
||
|
} else {
|
||
|
return Qundef;
|
||
|
}
|
||
|
} else {
|
||
|
if (vm_method_cfunc_is(ci, cc, recv, rb_false)) {
|
||
|
return Qfalse;
|
||
|
} else {
|
||
|
return Qundef;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
static VALUE
|
||
|
fix_succ(VALUE x)
|
||
|
{
|
||