From d2a176028f2975f305ff06ca6984e68f7cd022fe Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 15 Jan 2013 14:07:24 +0000 Subject: [PATCH] object.c: CLASS_OR_MODULE_P * object.c (rb_mod_to_s, rb_class_inherited_p, rb_mod_ge, rb_mod_cmp): use BUILTIN_TYPE() instead of TYPE() for optimization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/object.c b/object.c index bb4851da65..2aab66c5fd 100644 --- a/object.c +++ b/object.c @@ -39,6 +39,10 @@ static ID id_eq, id_eql, id_match, id_inspect; static ID id_init_copy, id_init_clone, id_init_dup; static ID id_const_missing; +#define CLASS_OR_MODULE_P(obj) \ + (!SPECIAL_CONST_P(obj) && \ + (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE)) + /* * call-seq: * obj === other -> true or false @@ -1352,13 +1356,11 @@ rb_mod_to_s(VALUE klass) VALUE s = rb_usascii_str_new2("#"); @@ -1429,11 +1431,7 @@ rb_class_inherited_p(VALUE mod, VALUE arg) VALUE start = mod; if (mod == arg) return Qtrue; - switch (TYPE(arg)) { - case T_MODULE: - case T_CLASS: - break; - default: + if (!CLASS_OR_MODULE_P(arg)) { rb_raise(rb_eTypeError, "compared with non class/module"); } while (mod) { @@ -1484,11 +1482,7 @@ rb_mod_lt(VALUE mod, VALUE arg) static VALUE rb_mod_ge(VALUE mod, VALUE arg) { - switch (TYPE(arg)) { - case T_MODULE: - case T_CLASS: - break; - default: + if (!CLASS_OR_MODULE_P(arg)) { rb_raise(rb_eTypeError, "compared with non class/module"); } @@ -1530,11 +1524,7 @@ rb_mod_cmp(VALUE mod, VALUE arg) VALUE cmp; if (mod == arg) return INT2FIX(0); - switch (TYPE(arg)) { - case T_MODULE: - case T_CLASS: - break; - default: + if (!CLASS_OR_MODULE_P(arg)) { return Qnil; }