Commit 09bb3087 authored by cremno's avatar cremno

tiny word boxing optimization

parent e8dd8180
...@@ -315,6 +315,7 @@ mrb_float_value(struct mrb_state *mrb, mrb_float f) ...@@ -315,6 +315,7 @@ mrb_float_value(struct mrb_state *mrb, mrb_float f)
#define mrb_bool(o) ((o).w != MRB_Qnil && (o).w != MRB_Qfalse) #define mrb_bool(o) ((o).w != MRB_Qnil && (o).w != MRB_Qfalse)
#else #else
#define mrb_cptr(o) mrb_ptr(o) #define mrb_cptr(o) mrb_ptr(o)
#define mrb_fixnum_p(o) (mrb_type(o) == MRB_TT_FIXNUM) #define mrb_fixnum_p(o) (mrb_type(o) == MRB_TT_FIXNUM)
#define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF) #define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF)
......
...@@ -7,7 +7,7 @@ r_le(mrb_state *mrb, mrb_value a, mrb_value b) ...@@ -7,7 +7,7 @@ r_le(mrb_state *mrb, mrb_value a, mrb_value b)
mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */ mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */
/* output :a < b => -1, a = b => 0, a > b => +1 */ /* output :a < b => -1, a = b => 0, a > b => +1 */
if (mrb_type(r) == MRB_TT_FIXNUM) { if (mrb_fixnum_p(r)) {
mrb_int c = mrb_fixnum(r); mrb_int c = mrb_fixnum(r);
if (c == 0 || c == -1) return TRUE; if (c == 0 || c == -1) return TRUE;
} }
...@@ -21,11 +21,7 @@ r_lt(mrb_state *mrb, mrb_value a, mrb_value b) ...@@ -21,11 +21,7 @@ r_lt(mrb_state *mrb, mrb_value a, mrb_value b)
mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b);
/* output :a < b => -1, a = b => 0, a > b => +1 */ /* output :a < b => -1, a = b => 0, a > b => +1 */
if (mrb_type(r) == MRB_TT_FIXNUM) { return mrb_fixnum_p(r) && mrb_fixnum(r) == -1;
if (mrb_fixnum(r) == -1) return TRUE;
}
return FALSE;
} }
/* /*
......
...@@ -318,7 +318,7 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1) ...@@ -318,7 +318,7 @@ mrb_ary_cmp(mrb_state *mrb, mrb_value ary1)
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
mrb_value v = ary_elt(ary2, i); mrb_value v = ary_elt(ary2, i);
r = mrb_funcall_argv(mrb, ary_elt(ary1, i), cmp, 1, &v); r = mrb_funcall_argv(mrb, ary_elt(ary1, i), cmp, 1, &v);
if (mrb_type(r) != MRB_TT_FIXNUM || mrb_fixnum(r) != 0) return r; if (!mrb_fixnum_p(r) || mrb_fixnum(r) != 0) return r;
} }
} }
len = a1->len - a2->len; len = a1->len - a2->len;
...@@ -697,7 +697,7 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self) ...@@ -697,7 +697,7 @@ mrb_ary_aget(mrb_state *mrb, mrb_value self)
return mrb_ary_ref(mrb, self, index); return mrb_ary_ref(mrb, self, index);
case 1: case 1:
if (mrb_type(argv[0]) != MRB_TT_FIXNUM) { if (!mrb_fixnum_p(argv[0])) {
mrb_raise(mrb, E_TYPE_ERROR, "expected Fixnum"); mrb_raise(mrb, E_TYPE_ERROR, "expected Fixnum");
} }
if (index < 0) index += a->len; if (index < 0) index += a->len;
......
...@@ -421,7 +421,7 @@ new_lit(codegen_scope *s, mrb_value val) ...@@ -421,7 +421,7 @@ new_lit(codegen_scope *s, mrb_value val)
case MRB_TT_FIXNUM: case MRB_TT_FIXNUM:
for (i=0; i<s->irep->plen; i++) { for (i=0; i<s->irep->plen; i++) {
pv = &s->irep->pool[i]; pv = &s->irep->pool[i];
if (mrb_type(*pv) != MRB_TT_FIXNUM) continue; if (!mrb_fixnum_p(*pv)) continue;
if (mrb_fixnum(*pv) == mrb_fixnum(val)) return i; if (mrb_fixnum(*pv) == mrb_fixnum(val)) return i;
} }
break; break;
......
...@@ -326,9 +326,9 @@ mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char *method) ...@@ -326,9 +326,9 @@ mrb_check_to_integer(mrb_state *mrb, mrb_value val, const char *method)
{ {
mrb_value v; mrb_value v;
if (mrb_type(val) == MRB_TT_FIXNUM) return val; if (mrb_fixnum_p(val)) return val;
v = convert_type(mrb, val, "Integer", method, FALSE); v = convert_type(mrb, val, "Integer", method, FALSE);
if (mrb_nil_p(v) || mrb_type(v) != MRB_TT_FIXNUM) { if (mrb_nil_p(v) || !mrb_fixnum_p(v)) {
return mrb_nil_value(); return mrb_nil_value();
} }
return v; return v;
...@@ -404,7 +404,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t) ...@@ -404,7 +404,7 @@ mrb_check_type(mrb_state *mrb, mrb_value x, enum mrb_vtype t)
if (mrb_nil_p(x)) { if (mrb_nil_p(x)) {
etype = "nil"; etype = "nil";
} }
else if (mrb_type(x) == MRB_TT_FIXNUM) { else if (mrb_fixnum_p(x)) {
etype = "Fixnum"; etype = "Fixnum";
} }
else if (mrb_type(x) == MRB_TT_SYMBOL) { else if (mrb_type(x) == MRB_TT_SYMBOL) {
......
...@@ -176,7 +176,7 @@ r_le(mrb_state *mrb, mrb_value a, mrb_value b) ...@@ -176,7 +176,7 @@ r_le(mrb_state *mrb, mrb_value a, mrb_value b)
mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */ mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */
/* output :a < b => -1, a = b => 0, a > b => +1 */ /* output :a < b => -1, a = b => 0, a > b => +1 */
if (mrb_type(r) == MRB_TT_FIXNUM) { if (mrb_fixnum_p(r)) {
mrb_int c = mrb_fixnum(r); mrb_int c = mrb_fixnum(r);
if (c == 0 || c == -1) return TRUE; if (c == 0 || c == -1) return TRUE;
} }
...@@ -190,11 +190,7 @@ r_gt(mrb_state *mrb, mrb_value a, mrb_value b) ...@@ -190,11 +190,7 @@ r_gt(mrb_state *mrb, mrb_value a, mrb_value b)
mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b);
/* output :a < b => -1, a = b => 0, a > b => +1 */ /* output :a < b => -1, a = b => 0, a > b => +1 */
if (mrb_type(r) == MRB_TT_FIXNUM) { return mrb_fixnum_p(r) && mrb_fixnum(r) == 1;
if (mrb_fixnum(r) == 1) return TRUE;
}
return FALSE;
} }
static mrb_bool static mrb_bool
...@@ -203,7 +199,7 @@ r_ge(mrb_state *mrb, mrb_value a, mrb_value b) ...@@ -203,7 +199,7 @@ r_ge(mrb_state *mrb, mrb_value a, mrb_value b)
mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */ mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */
/* output :a < b => -1, a = b => 0, a > b => +1 */ /* output :a < b => -1, a = b => 0, a > b => +1 */
if (mrb_type(r) == MRB_TT_FIXNUM) { if (mrb_fixnum_p(r)) {
mrb_int c = mrb_fixnum(r); mrb_int c = mrb_fixnum(r);
if (c == 0 || c == 1) return TRUE; if (c == 0 || c == 1) return TRUE;
} }
......
...@@ -1248,7 +1248,7 @@ mrb_str_include(mrb_state *mrb, mrb_value self) ...@@ -1248,7 +1248,7 @@ mrb_str_include(mrb_state *mrb, mrb_value self)
mrb_bool include_p; mrb_bool include_p;
mrb_get_args(mrb, "o", &str2); mrb_get_args(mrb, "o", &str2);
if (mrb_type(str2) == MRB_TT_FIXNUM) { if (mrb_fixnum_p(str2)) {
include_p = (memchr(RSTRING_PTR(self), mrb_fixnum(str2), RSTRING_LEN(self)) != NULL); include_p = (memchr(RSTRING_PTR(self), mrb_fixnum(str2), RSTRING_LEN(self)) != NULL);
} }
else { else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment