* range.c (range_each): treat fixnums specially to boost.

* numeric.c (num_step): remove rb_scan_args() for small speedup.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-01-08 06:05:08 +00:00
parent a89ac45548
commit 17065d47a6
4 changed files with 31 additions and 8 deletions

View File

@ -44,7 +44,7 @@ memfill(mem, size, val)
#define ARY_TMPLOCK FL_USER1 #define ARY_TMPLOCK FL_USER1
static void static inline void
rb_ary_modify_check(ary) rb_ary_modify_check(ary)
VALUE ary; VALUE ary;
{ {

10
eval.c
View File

@ -917,14 +917,19 @@ static VALUE trace_func = 0;
static int tracing = 0; static int tracing = 0;
static void call_trace_func _((char*,NODE*,VALUE,ID,VALUE)); static void call_trace_func _((char*,NODE*,VALUE,ID,VALUE));
#if 0
#define SET_CURRENT_SOURCE() (ruby_sourcefile = ruby_current_node->nd_file, \ #define SET_CURRENT_SOURCE() (ruby_sourcefile = ruby_current_node->nd_file, \
ruby_sourceline = nd_line(ruby_current_node)) ruby_sourceline = nd_line(ruby_current_node))
#else
#define SET_CURRENT_SOURCE() 0
#endif
void void
ruby_set_current_source() ruby_set_current_source()
{ {
if (ruby_current_node) { if (ruby_current_node) {
SET_CURRENT_SOURCE(); ruby_sourcefile = ruby_current_node->nd_file;
ruby_sourceline = nd_line(ruby_current_node);
} }
} }
@ -3390,7 +3395,6 @@ rb_eval(self, n)
break; break;
case NODE_NEWLINE: case NODE_NEWLINE:
ruby_sourcefile = node->nd_file;
ruby_sourceline = node->nd_nth; ruby_sourceline = node->nd_nth;
if (trace_func) { if (trace_func) {
call_trace_func("line", node, self, call_trace_func("line", node, self,
@ -4443,7 +4447,7 @@ rb_undefined(obj, id, argc, argv, call_status)
return rb_funcall2(obj, missing, argc+1, nargv); return rb_funcall2(obj, missing, argc+1, nargv);
} }
static VALUE static inline VALUE
call_cfunc(func, recv, len, argc, argv) call_cfunc(func, recv, len, argc, argv)
VALUE (*func)(); VALUE (*func)();
VALUE recv; VALUE recv;

View File

@ -850,12 +850,22 @@ num_step(argc, argv, from)
{ {
VALUE to, step; VALUE to, step;
if (rb_scan_args(argc, argv, "11", &to, &step) == 1) { if (argc == 1) {
to = argv[0];
step = INT2FIX(1); step = INT2FIX(1);
} }
else if (rb_equal(step, INT2FIX(0))) { else {
if (argc == 2) {
to = argv[0];
step = argv[1];
}
else {
rb_raise(rb_eArgError, "wrong number of arguments");
}
if (rb_equal(step, INT2FIX(0))) {
rb_raise(rb_eArgError, "step cannot be 0"); rb_raise(rb_eArgError, "step cannot be 0");
} }
}
if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) { if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) {
long i, end, diff; long i, end, diff;

11
range.c
View File

@ -306,7 +306,16 @@ range_each(range)
rb_raise(rb_eTypeError, "cannot iterate from %s", rb_raise(rb_eTypeError, "cannot iterate from %s",
rb_class2name(CLASS_OF(beg))); rb_class2name(CLASS_OF(beg)));
} }
if (TYPE(beg) == T_STRING) { if (FIXNUM_P(beg) && FIXNUM_P(end)) { /* fixnums are special */
long lim = FIX2LONG(end);
long i;
if (!EXCL(range)) lim += 1;
for (i=FIX2LONG(beg); i<lim; i++) {
rb_yield(LONG2NUM(i));
}
}
else if (TYPE(beg) == T_STRING) {
VALUE args[5]; VALUE args[5];
long iter[2]; long iter[2];