summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-25 05:42:28 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-25 05:42:28 +0000
commit9c5a4caf72e0674f19e346487f6acb0dafab22c1 (patch)
treea0586302c5b27b99a5dfad0851a19877f0c92952 /range.c
parent689cc98238867859689928d07f9355dd181274ff (diff)
* range.c (range_max): treat end exclusion without iteration if
the end value is an integer. [ruby-talk:167433] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/range.c b/range.c
index f3f1f3191c..12ea69daaa 100644
--- a/range.c
+++ b/range.c
@@ -457,8 +457,7 @@ range_min(VALUE range)
else {
VALUE b = rb_ivar_get(range, id_beg);
VALUE e = rb_ivar_get(range, id_end);
- VALUE r = rb_funcall(b, id_cmp, 1, e);
- int c = rb_cmpint(r, b, e);
+ int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);
if (c > 0) return Qnil;
return b;
@@ -480,16 +479,23 @@ range_min(VALUE range)
static VALUE
range_max(VALUE range)
{
- if (rb_block_given_p() || EXCL(range)) {
+ VALUE e = rb_ivar_get(range, id_end);
+ int ip = FIXNUM_P(e) || rb_obj_is_kind_of(e, rb_cInteger);
+
+ if (rb_block_given_p() || (EXCL(range) && !ip)) {
return rb_call_super(0, 0);
}
else {
VALUE b = rb_ivar_get(range, id_beg);
- VALUE e = rb_ivar_get(range, id_end);
- VALUE r = rb_funcall(b, id_cmp, 1, e);
- int c = rb_cmpint(r, b, e);
+ int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);
if (c > 0) return Qnil;
+ if (EXCL(range)) {
+ if (FIXNUM_P(e)) {
+ return INT2NUM(FIX2INT(e)-1);
+ }
+ return rb_funcall(e, '-', 1, INT2FIX(1));
+ }
return e;
}
}