mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
a89ac45548
commit
17065d47a6
4 changed files with 31 additions and 8 deletions
2
array.c
2
array.c
|
@ -44,7 +44,7 @@ memfill(mem, size, val)
|
|||
|
||||
#define ARY_TMPLOCK FL_USER1
|
||||
|
||||
static void
|
||||
static inline void
|
||||
rb_ary_modify_check(ary)
|
||||
VALUE ary;
|
||||
{
|
||||
|
|
10
eval.c
10
eval.c
|
@ -917,14 +917,19 @@ static VALUE trace_func = 0;
|
|||
static int tracing = 0;
|
||||
static void call_trace_func _((char*,NODE*,VALUE,ID,VALUE));
|
||||
|
||||
#if 0
|
||||
#define SET_CURRENT_SOURCE() (ruby_sourcefile = ruby_current_node->nd_file, \
|
||||
ruby_sourceline = nd_line(ruby_current_node))
|
||||
#else
|
||||
#define SET_CURRENT_SOURCE() 0
|
||||
#endif
|
||||
|
||||
void
|
||||
ruby_set_current_source()
|
||||
{
|
||||
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;
|
||||
|
||||
case NODE_NEWLINE:
|
||||
ruby_sourcefile = node->nd_file;
|
||||
ruby_sourceline = node->nd_nth;
|
||||
if (trace_func) {
|
||||
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);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
static inline VALUE
|
||||
call_cfunc(func, recv, len, argc, argv)
|
||||
VALUE (*func)();
|
||||
VALUE recv;
|
||||
|
|
16
numeric.c
16
numeric.c
|
@ -850,11 +850,21 @@ num_step(argc, argv, from)
|
|||
{
|
||||
VALUE to, step;
|
||||
|
||||
if (rb_scan_args(argc, argv, "11", &to, &step) == 1) {
|
||||
if (argc == 1) {
|
||||
to = argv[0];
|
||||
step = INT2FIX(1);
|
||||
}
|
||||
else if (rb_equal(step, INT2FIX(0))) {
|
||||
rb_raise(rb_eArgError, "step cannot be 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");
|
||||
}
|
||||
}
|
||||
|
||||
if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) {
|
||||
|
|
11
range.c
11
range.c
|
@ -306,7 +306,16 @@ range_each(range)
|
|||
rb_raise(rb_eTypeError, "cannot iterate from %s",
|
||||
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];
|
||||
long iter[2];
|
||||
|
||||
|
|
Loading…
Reference in a new issue