ruby-changes:50456
From: mrkn <ko1@a...>
Date: Mon, 26 Feb 2018 16:57:20 +0900 (JST)
Subject: [ruby-changes:50456] mrkn:r62582 (trunk): Use RB_INTEGER_TYPE_P instead of rb_obj_is_kind_of
mrkn 2018-02-26 16:57:15 +0900 (Mon, 26 Feb 2018) New Revision: 62582 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62582 Log: Use RB_INTEGER_TYPE_P instead of rb_obj_is_kind_of For checking whether an object is an Integer, because a subclass of Integer is meaningless in Ruby, RB_INTEGER_TYPE_P is better than rb_obj_is_kind_of for speed. * object.c (rb_to_integer): Use RB_INTEGER_TYPE_P instead of rb_obj_is_kind_of. * object.c (rb_check_to_integer): ditto. * range.c (range_max): ditto. Modified files: trunk/object.c trunk/range.c Index: object.c =================================================================== --- object.c (revision 62581) +++ object.c (revision 62582) @@ -3043,8 +3043,8 @@ rb_to_integer(VALUE val, const char *met https://github.com/ruby/ruby/blob/trunk/object.c#L3043 if (FIXNUM_P(val)) return val; if (RB_TYPE_P(val, T_BIGNUM)) return val; v = convert_type(val, "Integer", method, TRUE); - if (!rb_obj_is_kind_of(v, rb_cInteger)) { - conversion_mismatch(val, "Integer", method, v); + if (!RB_INTEGER_TYPE_P(v)) { + conversion_mismatch(val, "Integer", method, v); } return v; } @@ -3067,8 +3067,8 @@ rb_check_to_integer(VALUE val, const cha https://github.com/ruby/ruby/blob/trunk/object.c#L3067 if (FIXNUM_P(val)) return val; if (RB_TYPE_P(val, T_BIGNUM)) return val; v = convert_type(val, "Integer", method, FALSE); - if (!rb_obj_is_kind_of(v, rb_cInteger)) { - return Qnil; + if (!RB_INTEGER_TYPE_P(v)) { + return Qnil; } return v; } Index: range.c =================================================================== --- range.c (revision 62581) +++ range.c (revision 62582) @@ -949,29 +949,29 @@ range_max(int argc, VALUE *argv, VALUE r https://github.com/ruby/ruby/blob/trunk/range.c#L949 int nm = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cNumeric); if (rb_block_given_p() || (EXCL(range) && !nm) || argc) { - return rb_call_super(argc, argv); + return rb_call_super(argc, argv); } else { - struct cmp_opt_data cmp_opt = { 0, 0 }; - VALUE b = RANGE_BEG(range); - int c = OPTIMIZED_CMP(b, e, cmp_opt); + struct cmp_opt_data cmp_opt = { 0, 0 }; + VALUE b = RANGE_BEG(range); + int c = OPTIMIZED_CMP(b, e, cmp_opt); - if (c > 0) - return Qnil; - if (EXCL(range)) { - if (!FIXNUM_P(e) && !rb_obj_is_kind_of(e, rb_cInteger)) { - rb_raise(rb_eTypeError, "cannot exclude non Integer end value"); - } - if (c == 0) return Qnil; - if (!FIXNUM_P(b) && !rb_obj_is_kind_of(b,rb_cInteger)) { - rb_raise(rb_eTypeError, "cannot exclude end value with non Integer begin value"); - } - if (FIXNUM_P(e)) { - return LONG2NUM(FIX2LONG(e) - 1); - } - return rb_funcall(e, '-', 1, INT2FIX(1)); - } - return e; + if (c > 0) + return Qnil; + if (EXCL(range)) { + if (!RB_INTEGER_TYPE_P(e)) { + rb_raise(rb_eTypeError, "cannot exclude non Integer end value"); + } + if (c == 0) return Qnil; + if (!RB_INTEGER_TYPE_P(b)) { + rb_raise(rb_eTypeError, "cannot exclude end value with non Integer begin value"); + } + if (FIXNUM_P(e)) { + return LONG2NUM(FIX2LONG(e) - 1); + } + return rb_funcall(e, '-', 1, INT2FIX(1)); + } + return e; } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/