summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-08 06:05:08 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-08 06:05:08 +0000
commit17065d47a68eaa6a854297b94e4d85d379b23f2d (patch)
tree670a5d87beb9be1833869225ce4722607327f4ba
parenta89ac45548573342400a563b407f13a8d5b06841 (diff)
* 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
-rw-r--r--array.c2
-rw-r--r--eval.c10
-rw-r--r--numeric.c16
-rw-r--r--range.c11
4 files changed, 31 insertions, 8 deletions
diff --git a/array.c b/array.c
index 934fb36489..1313093a53 100644
--- a/array.c
+++ b/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;
{
diff --git a/eval.c b/eval.c
index 2a25dac31a..fbe53d8daf 100644
--- a/eval.c
+++ b/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;
diff --git a/numeric.c b/numeric.c
index 28061cad56..04c59f4ae0 100644
--- a/numeric.c
+++ b/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)) {
diff --git a/range.c b/range.c
index 3b56ee7d0b..2faf2f3489 100644
--- a/range.c
+++ b/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];