summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-14 16:39:15 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-14 16:39:15 +0000
commit6a60393280046a4991da8a415a77c60c7be240b5 (patch)
tree489d3ac0bc9d172e33965204600726fd5d4dbbef /range.c
parent35ae7c90450157e1d8d415be819da40c9c1289a6 (diff)
* range.c (range_each_func): terminates loop if generating value
is same to @end. [ruby-talk:100269] * string.c (rb_str_new4): should not reuse frozen shared string if the original is not an instance of String. [ruby-talk:100193] * time.c (time_mdump): preserve GMT bit in the marshal data. [ruby-talk:100213] * eval.c (is_defined): do not protect exception during receiver evaluation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/range.c b/range.c
index 66e6070cf8..46cc6d0bc8 100644
--- a/range.c
+++ b/range.c
@@ -155,10 +155,13 @@ static int
r_le(a, b)
VALUE a, b;
{
+ int c;
VALUE r = rb_funcall(a, id_cmp, 1, b);
if (NIL_P(r)) return Qfalse;
- if (rb_cmpint(r, a, b) <= 0) return Qtrue;
+ c = rb_cmpint(r, a, b);
+ if (c == 0) return INT2FIX(0);
+ if (c < 0) return Qtrue;
return Qfalse;
}
@@ -247,6 +250,8 @@ range_each_func(range, func, v, e, arg)
VALUE v, e;
void *arg;
{
+ int c;
+
if (EXCL(range)) {
while (r_lt(v, e)) {
(*func)(v, arg);
@@ -254,8 +259,9 @@ range_each_func(range, func, v, e, arg)
}
}
else {
- while (r_le(v, e)) {
+ while (RTEST(c = r_le(v, e))) {
(*func)(v, arg);
+ if (c == INT2FIX(0)) break;
v = rb_funcall(v, id_succ, 0, 0);
}
}