summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-14 16:35:30 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-14 16:35:30 +0000
commit58f3410e53bdc62343123891e0225a710b515554 (patch)
tree2aa48325d5a89004997add9617e3e9967e5ea7c8 /range.c
parent0cf6e773be4ab563decd19c6a285568e489e80ea (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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6312 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 66e6070..46cc6d0 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);
}
}