Permalink
Browse files

* use RB_TYPE_P which is optimized for constant types, instead of

  comparison with TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33357 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent 68f97d7 commit 8e6e8e628888aa251f771ce8b3fe30a6b41a7a0e @nobu nobu committed Sep 29, 2011
Showing with 164 additions and 159 deletions.
  1. +5 −0 ChangeLog
  2. +4 −4 array.c
  3. +8 −8 bignum.c
  4. +10 −10 class.c
  5. +4 −4 compile.c
  6. +5 −5 complex.c
  7. +1 −1 enum.c
  8. +1 −1 enumerator.c
  9. +1 −1 error.c
  10. +1 −1 eval.c
  11. +2 −2 eval_error.c
  12. +2 −2 gc.c
  13. +2 −2 hash.c
  14. +12 −12 io.c
  15. +9 −9 marshal.c
  16. +1 −1 math.c
  17. +5 −5 numeric.c
  18. +6 −6 object.c
  19. +3 −3 pack.c
  20. +1 −1 parse.y
  21. +3 −3 proc.c
  22. +3 −3 process.c
  23. +2 −2 random.c
  24. +3 −3 range.c
  25. +5 −5 rational.c
  26. +3 −3 re.c
  27. +1 −1 ruby.c
  28. +1 −1 safe.c
  29. +13 −13 string.c
  30. +6 −6 struct.c
  31. +7 −7 thread.c
  32. +16 −16 time.c
  33. +4 −4 transcode.c
  34. +3 −3 variable.c
  35. +4 −4 vm_eval.c
  36. +3 −3 vm_insnhelper.c
  37. +4 −4 vm_method.c
View
@@ -1,3 +1,8 @@
+Thu Sep 29 20:07:36 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * use RB_TYPE_P which is optimized for constant types, instead of
+ comparison with TYPE.
+
Wed Sep 28 09:20:37 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (pthread_np.h): needs pthread.h to be included
View
@@ -2016,7 +2016,7 @@ enum {
sort_optimizable_count
};
-#define STRING_P(s) (TYPE(s) == T_STRING && CLASS_OF(s) == rb_cString)
+#define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
#define SORT_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(sort_opt_,type))
#define SORT_OPTIMIZABLE(data, type) \
@@ -3137,7 +3137,7 @@ rb_ary_rassoc(VALUE ary, VALUE value)
for (i = 0; i < RARRAY_LEN(ary); ++i) {
v = RARRAY_PTR(ary)[i];
- if (TYPE(v) == T_ARRAY &&
+ if (RB_TYPE_P(v, T_ARRAY) &&
RARRAY_LEN(v) > 1 &&
rb_equal(RARRAY_PTR(v)[1], value))
return v;
@@ -3176,7 +3176,7 @@ static VALUE
rb_ary_equal(VALUE ary1, VALUE ary2)
{
if (ary1 == ary2) return Qtrue;
- if (TYPE(ary2) != T_ARRAY) {
+ if (!RB_TYPE_P(ary2, T_ARRAY)) {
if (!rb_respond_to(ary2, rb_intern("to_ary"))) {
return Qfalse;
}
@@ -3211,7 +3211,7 @@ static VALUE
rb_ary_eql(VALUE ary1, VALUE ary2)
{
if (ary1 == ary2) return Qtrue;
- if (TYPE(ary2) != T_ARRAY) return Qfalse;
+ if (!RB_TYPE_P(ary2, T_ARRAY)) return Qfalse;
if (RARRAY_LEN(ary1) != RARRAY_LEN(ary2)) return Qfalse;
return rb_exec_recursive_paired(recursive_eql, ary1, ary2, ary2);
}
View
@@ -101,7 +101,7 @@ rb_cmpint(VALUE val, VALUE a, VALUE b)
if (l < 0) return -1;
return 0;
}
- if (TYPE(val) == T_BIGNUM) {
+ if (RB_TYPE_P(val, T_BIGNUM)) {
if (BIGZEROP(val)) return 0;
if (RBIGNUM_SIGN(val)) return 1;
return -1;
@@ -269,7 +269,7 @@ bigfixize(VALUE x)
static VALUE
bignorm(VALUE x)
{
- if (!FIXNUM_P(x) && TYPE(x) == T_BIGNUM) {
+ if (RB_TYPE_P(x, T_BIGNUM)) {
x = bigfixize(bigtrunc(x));
}
return x;
@@ -1628,7 +1628,7 @@ rb_big_eq(VALUE x, VALUE y)
static VALUE
rb_big_eql(VALUE x, VALUE y)
{
- if (TYPE(y) != T_BIGNUM) return Qfalse;
+ if (!RB_TYPE_P(y, T_BIGNUM)) return Qfalse;
if (RBIGNUM_SIGN(x) != RBIGNUM_SIGN(y)) return Qfalse;
if (RBIGNUM_LEN(x) != RBIGNUM_LEN(y)) return Qfalse;
if (MEMCMP(BDIGITS(x),BDIGITS(y),BDIGIT,RBIGNUM_LEN(y)) != 0) return Qfalse;
@@ -3107,7 +3107,7 @@ rb_big_pow(VALUE x, VALUE y)
static inline VALUE
bit_coerce(VALUE x)
{
- while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) {
+ while (!FIXNUM_P(x) && !RB_TYPE_P(x, T_BIGNUM)) {
rb_raise(rb_eTypeError,
"can't convert %s into Integer for bitwise arithmetic",
rb_obj_classname(x));
@@ -3434,7 +3434,7 @@ rb_big_lshift(VALUE x, VALUE y)
}
break;
}
- else if (TYPE(y) == T_BIGNUM) {
+ else if (RB_TYPE_P(y, T_BIGNUM)) {
if (!RBIGNUM_SIGN(y)) {
VALUE t = check_shiftdown(y, x);
if (!NIL_P(t)) return t;
@@ -3498,7 +3498,7 @@ rb_big_rshift(VALUE x, VALUE y)
}
break;
}
- else if (TYPE(y) == T_BIGNUM) {
+ else if (RB_TYPE_P(y, T_BIGNUM)) {
if (RBIGNUM_SIGN(y)) {
VALUE t = check_shiftdown(y, x);
if (!NIL_P(t)) return t;
@@ -3586,7 +3586,7 @@ rb_big_aref(VALUE x, VALUE y)
VALUE shift;
long i, s1, s2;
- if (TYPE(y) == T_BIGNUM) {
+ if (RB_TYPE_P(y, T_BIGNUM)) {
if (!RBIGNUM_SIGN(y))
return INT2FIX(0);
bigtrunc(y);
@@ -3646,7 +3646,7 @@ rb_big_coerce(VALUE x, VALUE y)
if (FIXNUM_P(y)) {
return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
}
- else if (TYPE(y) == T_BIGNUM) {
+ else if (RB_TYPE_P(y, T_BIGNUM)) {
return rb_assoc_new(y, x);
}
else {
View
@@ -93,7 +93,7 @@ rb_class_boot(VALUE super)
void
rb_check_inheritable(VALUE super)
{
- if (TYPE(super) != T_CLASS) {
+ if (!RB_TYPE_P(super, T_CLASS)) {
rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
rb_obj_classname(super));
}
@@ -463,7 +463,7 @@ rb_define_class(const char *name, VALUE super)
id = rb_intern(name);
if (rb_const_defined(rb_cObject, id)) {
klass = rb_const_get(rb_cObject, id);
- if (TYPE(klass) != T_CLASS) {
+ if (!RB_TYPE_P(klass, T_CLASS)) {
rb_raise(rb_eTypeError, "%s is not a class", name);
}
if (rb_class_real(RCLASS_SUPER(klass)) != super) {
@@ -530,7 +530,7 @@ rb_define_class_id_under(VALUE outer, ID id, VALUE super)
if (rb_const_defined_at(outer, id)) {
klass = rb_const_get_at(outer, id);
- if (TYPE(klass) != T_CLASS) {
+ if (!RB_TYPE_P(klass, T_CLASS)) {
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
}
if (rb_class_real(RCLASS_SUPER(klass)) != super) {
@@ -581,7 +581,7 @@ rb_define_module(const char *name)
id = rb_intern(name);
if (rb_const_defined(rb_cObject, id)) {
module = rb_const_get(rb_cObject, id);
- if (TYPE(module) == T_MODULE)
+ if (RB_TYPE_P(module, T_MODULE))
return module;
rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
}
@@ -605,7 +605,7 @@ rb_define_module_id_under(VALUE outer, ID id)
if (rb_const_defined_at(outer, id)) {
module = rb_const_get_at(outer, id);
- if (TYPE(module) == T_MODULE)
+ if (RB_TYPE_P(module, T_MODULE))
return module;
rb_raise(rb_eTypeError, "%s::%s is not a module",
rb_class2name(outer), rb_obj_classname(module));
@@ -636,7 +636,7 @@ include_class_new(VALUE module, VALUE super)
RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
RCLASS_SUPER(klass) = super;
- if (TYPE(module) == T_ICLASS) {
+ if (RB_TYPE_P(module, T_ICLASS)) {
RBASIC(klass)->klass = RBASIC(module)->klass;
}
else {
@@ -659,7 +659,7 @@ rb_include_module(VALUE klass, VALUE module)
rb_secure(4);
}
- if (TYPE(module) != T_MODULE) {
+ if (!RB_TYPE_P(module, T_MODULE)) {
Check_Type(module, T_MODULE);
}
@@ -791,7 +791,7 @@ rb_mix_module(VALUE klass, VALUE module, st_table *constants, st_table *methods)
rb_secure(4);
}
- if (TYPE(module) != T_MODULE) {
+ if (!RB_TYPE_P(module, T_MODULE)) {
Check_Type(module, T_MODULE);
}
@@ -1248,7 +1248,7 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
klass = RCLASS_SUPER(klass);
}
if (RTEST(recur)) {
- while (klass && (FL_TEST(klass, FL_SINGLETON) || TYPE(klass) == T_ICLASS)) {
+ while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
st_foreach(RCLASS_M_TBL(klass), method_entry_i, (st_data_t)list);
klass = RCLASS_SUPER(klass);
}
@@ -1435,7 +1435,7 @@ rb_singleton_class(VALUE obj)
VALUE klass = singleton_class_of(obj);
/* ensures an exposed class belongs to its own eigenclass */
- if (TYPE(obj) == T_CLASS) (void)ENSURE_EIGENCLASS(klass);
+ if (RB_TYPE_P(obj, T_CLASS)) (void)ENSURE_EIGENCLASS(klass);
return klass;
}
View
@@ -1263,7 +1263,7 @@ static st_index_t
cdhash_hash(VALUE a)
{
if (SPECIAL_CONST_P(a)) return (st_index_t)a;
- if (TYPE(a) == T_STRING) return rb_str_hash(a);
+ if (RB_TYPE_P(a, T_STRING)) return rb_str_hash(a);
{
VALUE hval = rb_hash(a);
return (st_index_t)FIX2LONG(hval);
@@ -2335,7 +2335,7 @@ case_when_optimizable_literal(NODE * node)
case NODE_LIT: {
VALUE v = node->nd_lit;
double ival;
- if (TYPE(v) == T_FLOAT &&
+ if (RB_TYPE_P(v, T_FLOAT) &&
modf(RFLOAT_VALUE(v), &ival) == 0.0) {
return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
}
@@ -5314,7 +5314,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor,
else if (FIXNUM_P(obj)) {
line_no = NUM2INT(obj);
}
- else if (TYPE(obj) == T_ARRAY) {
+ else if (RB_TYPE_P(obj, T_ARRAY)) {
VALUE *argv = 0;
int argc = RARRAY_LENINT(obj) - 1;
st_data_t insn_id;
@@ -5356,7 +5356,7 @@ iseq_build_from_ary_body(rb_iseq_t *iseq, LINK_ANCHOR *anchor,
case TS_ISEQ:
{
if (op != Qnil) {
- if (TYPE(op) == T_ARRAY) {
+ if (RB_TYPE_P(op, T_ARRAY)) {
argv[j] = rb_iseq_load(op, iseq->self, Qnil);
}
else if (CLASS_OF(op) == rb_cISeq) {
View
@@ -121,7 +121,7 @@ f_mul(VALUE x, VALUE y)
if (FIXNUM_P(y)) {
long iy = FIX2LONG(y);
if (iy == 0) {
- if (FIXNUM_P(x) || TYPE(x) == T_BIGNUM)
+ if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
return ZERO;
}
else if (iy == 1)
@@ -130,7 +130,7 @@ f_mul(VALUE x, VALUE y)
else if (FIXNUM_P(x)) {
long ix = FIX2LONG(x);
if (ix == 0) {
- if (FIXNUM_P(y) || TYPE(y) == T_BIGNUM)
+ if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM))
return ZERO;
}
else if (ix == 1)
@@ -166,14 +166,14 @@ fun1(real_p)
inline static VALUE
f_to_i(VALUE x)
{
- if (TYPE(x) == T_STRING)
+ if (RB_TYPE_P(x, T_STRING))
return rb_str_to_inum(x, 10, 0);
return rb_funcall(x, id_to_i, 0);
}
inline static VALUE
f_to_f(VALUE x)
{
- if (TYPE(x) == T_STRING)
+ if (RB_TYPE_P(x, T_STRING))
return DBL2NUM(rb_str_to_dbl(x, 0));
return rb_funcall(x, id_to_f, 0);
}
@@ -944,7 +944,7 @@ nucomp_coerce(VALUE self, VALUE other)
{
if (k_numeric_p(other) && f_real_p(other))
return rb_assoc_new(f_complex_new_bang1(CLASS_OF(self), other), self);
- if (TYPE(other) == T_COMPLEX)
+ if (RB_TYPE_P(other, T_COMPLEX))
return rb_assoc_new(other, self);
rb_raise(rb_eTypeError, "%s can't be coerced into %s",
View
@@ -901,7 +901,7 @@ enum_sort_by(VALUE obj)
RETURN_ENUMERATOR(obj, 0, 0);
- if (TYPE(obj) == T_ARRAY && RARRAY_LEN(obj) <= LONG_MAX/2) {
+ if (RB_TYPE_P(obj, T_ARRAY) && RARRAY_LEN(obj) <= LONG_MAX/2) {
ary = rb_ary_new2(RARRAY_LEN(obj)*2);
}
else {
View
@@ -590,7 +590,7 @@ enumerator_next_values(VALUE obj)
static VALUE
ary2sv(VALUE args, int dup)
{
- if (TYPE(args) != T_ARRAY)
+ if (!RB_TYPE_P(args, T_ARRAY))
return args;
switch (RARRAY_LEN(args)) {
View
@@ -1134,7 +1134,7 @@ syserr_initialize(int argc, VALUE *argv, VALUE self)
if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
klass = (VALUE)data;
/* change class */
- if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
+ if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */
rb_raise(rb_eTypeError, "invalid instance type");
}
RBASIC(self)->klass = klass;
View
@@ -169,7 +169,7 @@ ruby_cleanup(volatile int ex)
if (!RTEST(err)) continue;
/* th->errinfo contains a NODE while break'ing */
- if (TYPE(err) == T_NODE) continue;
+ if (RB_TYPE_P(err, T_NODE)) continue;
if (rb_obj_is_kind_of(err, rb_eSystemExit)) {
ex = sysexit_status(err);
View
@@ -202,7 +202,7 @@ rb_print_undef(VALUE klass, ID id, int scope)
}
rb_name_error(id, "undefined%s method `%s' for %s `%s'", v,
rb_id2name(id),
- (TYPE(klass) == T_MODULE) ? "module" : "class",
+ (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
rb_class2name(klass));
}
@@ -211,7 +211,7 @@ rb_print_undef_str(VALUE klass, VALUE name)
{
rb_name_error_str(name, "undefined method `%s' for %s `%s'",
RSTRING_PTR(name),
- (TYPE(klass) == T_MODULE) ? "module" : "class",
+ (RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
rb_class2name(klass));
}
View
@@ -3265,7 +3265,7 @@ count_objects(int argc, VALUE *argv, VALUE os)
VALUE hash;
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
- if (TYPE(hash) != T_HASH)
+ if (!RB_TYPE_P(hash, T_HASH))
rb_raise(rb_eTypeError, "non-hash given");
}
@@ -3384,7 +3384,7 @@ gc_stat(int argc, VALUE *argv, VALUE self)
VALUE hash;
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
- if (TYPE(hash) != T_HASH)
+ if (!RB_TYPE_P(hash, T_HASH))
rb_raise(rb_eTypeError, "non-hash given");
}
View
@@ -44,7 +44,7 @@ rb_any_cmp(VALUE a, VALUE b)
if (FIXNUM_P(a) && FIXNUM_P(b)) {
return a != b;
}
- if (TYPE(a) == T_STRING && RBASIC(a)->klass == rb_cString &&
+ if (RB_TYPE_P(a, T_STRING) && RBASIC(a)->klass == rb_cString &&
TYPE(b) == T_STRING && RBASIC(b)->klass == rb_cString) {
return rb_str_hash_cmp(a, b);
}
@@ -1599,7 +1599,7 @@ hash_equal(VALUE hash1, VALUE hash2, int eql)
struct equal_data data;
if (hash1 == hash2) return Qtrue;
- if (TYPE(hash2) != T_HASH) {
+ if (!RB_TYPE_P(hash2, T_HASH)) {
if (!rb_respond_to(hash2, rb_intern("to_hash"))) {
return Qfalse;
}
Oops, something went wrong.

0 comments on commit 8e6e8e6

Please sign in to comment.