summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-26 07:57:15 (GMT)
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-26 07:57:15 (GMT)
commit2234edf0b1183e0d6f63ac093243fc6e23e15dd5 (patch)
tree366e0950459b1f285413a3de5a3b19a5b8a4fc58 /range.c
parentcc4be225a8c1dd5f42a4c4b6356b0b351b6e85d5 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/range.c b/range.c
index 5897557..828231f 100644
--- a/range.c
+++ b/range.c
@@ -949,29 +949,29 @@ range_max(int argc, VALUE *argv, VALUE range)
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);
-
- 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;
+ 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 (!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;
}
}