summaryrefslogtreecommitdiffstats
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-23 15:46:02 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-23 15:46:02 +0000
commitec4fcf3c171ad5d4026663b2d241740040d9994c (patch)
tree7bac4862a60a8adac7e4f3153eb34844759687a8 /range.c
parent26fbb3c2ff7a04622f438cd6a3047c864d1b2a03 (diff)
downloadruby-ec4fcf3c171ad5d4026663b2d241740040d9994c.tar.gz
ruby-ec4fcf3c171ad5d4026663b2d241740040d9994c.tar.xz
ruby-ec4fcf3c171ad5d4026663b2d241740040d9994c.zip
* range.c (range_each): check #succ only when it is really
needed. small performance improvement. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@22574 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/range.c b/range.c
index 6e0af8679..02a75e700 100644
--- a/range.c
+++ b/range.c
@@ -417,10 +417,6 @@ range_each(VALUE range)
beg = RANGE_BEG(range);
end = RANGE_END(range);
- if (!rb_respond_to(beg, id_succ)) {
- rb_raise(rb_eTypeError, "can't iterate from %s",
- rb_obj_classname(beg));
- }
if (FIXNUM_P(beg) && FIXNUM_P(end)) { /* fixnums are special */
long lim = FIX2LONG(end);
long i;
@@ -439,6 +435,10 @@ range_each(VALUE range)
rb_block_call(beg, rb_intern("upto"), 2, args, rb_yield, 0);
}
else {
+ if (!rb_respond_to(beg, id_succ)) {
+ rb_raise(rb_eTypeError, "can't iterate from %s",
+ rb_obj_classname(beg));
+ }
range_each_func(range, each_i, NULL);
}
return range;