* numeric.c (fix_to_s): avoid rb_scan_args() when no argument

given. 
* bignum.c (rb_big_to_s): ditto.
* enum.c (enum_first): ditto.
* eval_jump.c (rb_f_catch): ditto.
* io.c (rb_obj_display): ditto.
* class.c (rb_obj_singleton_methods): ditto.
* object.c (rb_class_initialize): ditto.
* random.c (rb_f_srand): ditto.
* range.c (range_step): ditto.
* re.c (rb_reg_s_last_match): ditto.
* string.c (rb_str_to_i): ditto.
* string.c (rb_str_each_line): ditto.
* string.c (rb_str_chomp_bang): ditto.
* string.c (rb_str_sum): ditto.

* string.c (str_modifiable): declare inline.
* string.c (str_independent): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-03-05 05:22:17 +00:00
Родитель 413db1b036
Коммит 39787ea14d
15 изменённых файлов: 106 добавлений и 54 удалений

Просмотреть файл

@ -1,3 +1,24 @@
Wed Mar 5 14:00:49 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (fix_to_s): avoid rb_scan_args() when no argument
given.
* bignum.c (rb_big_to_s): ditto.
* enum.c (enum_first): ditto.
* eval_jump.c (rb_f_catch): ditto.
* io.c (rb_obj_display): ditto.
* class.c (rb_obj_singleton_methods): ditto.
* object.c (rb_class_initialize): ditto.
* random.c (rb_f_srand): ditto.
* range.c (range_step): ditto.
* re.c (rb_reg_s_last_match): ditto.
* string.c (rb_str_to_i): ditto.
* string.c (rb_str_each_line): ditto.
* string.c (rb_str_chomp_bang): ditto.
* string.c (rb_str_sum): ditto.
* string.c (str_modifiable): declare inline.
* string.c (str_independent): ditto.
Wed Mar 5 11:50:32 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/debug.rb: require 'continuation' to implement "restart"

32
array.c
Просмотреть файл

@ -290,7 +290,7 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
VALUE size, val;
rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
if (argc == 0) {
if (RARRAY_PTR(ary) && !ARY_SHARED_P(ary)) {
free(RARRAY(ary)->ptr);
}
@ -300,7 +300,7 @@ rb_ary_initialize(int argc, VALUE *argv, VALUE ary)
}
return ary;
}
rb_scan_args(argc, argv, "02", &size, &val);
if (argc == 1 && !FIXNUM_P(size)) {
val = rb_check_array_type(size);
if (!NIL_P(val)) {
@ -877,19 +877,19 @@ rb_ary_index(int argc, VALUE *argv, VALUE ary)
VALUE val;
long i;
if (rb_scan_args(argc, argv, "01", &val) == 0) {
if (argc == 0) {
RETURN_ENUMERATOR(ary, 0, 0);
for (i=0; i<RARRAY_LEN(ary); i++) {
if (RTEST(rb_yield(RARRAY_PTR(ary)[i]))) {
return LONG2NUM(i);
}
}
return Qnil;
}
else {
for (i=0; i<RARRAY_LEN(ary); i++) {
if (rb_equal(RARRAY_PTR(ary)[i], val))
return LONG2NUM(i);
}
rb_scan_args(argc, argv, "01", &val);
for (i=0; i<RARRAY_LEN(ary); i++) {
if (rb_equal(RARRAY_PTR(ary)[i], val))
return LONG2NUM(i);
}
return Qnil;
}
@ -915,7 +915,7 @@ rb_ary_rindex(int argc, VALUE *argv, VALUE ary)
VALUE val;
long i = RARRAY_LEN(ary);
if (rb_scan_args(argc, argv, "01", &val) == 0) {
if (argc == 0) {
RETURN_ENUMERATOR(ary, 0, 0);
while (i--) {
if (RTEST(rb_yield(RARRAY_PTR(ary)[i])))
@ -924,14 +924,14 @@ rb_ary_rindex(int argc, VALUE *argv, VALUE ary)
i = RARRAY_LEN(ary);
}
}
return Qnil;
}
else {
while (i--) {
if (rb_equal(RARRAY_PTR(ary)[i], val))
return LONG2NUM(i);
if (i > RARRAY_LEN(ary)) {
i = RARRAY_LEN(ary);
}
rb_scan_args(argc, argv, "01", &val);
while (i--) {
if (rb_equal(RARRAY_PTR(ary)[i], val))
return LONG2NUM(i);
if (i > RARRAY_LEN(ary)) {
i = RARRAY_LEN(ary);
}
}
return Qnil;

Просмотреть файл

@ -987,12 +987,15 @@ rb_big2str(VALUE x, int base)
static VALUE
rb_big_to_s(int argc, VALUE *argv, VALUE x)
{
VALUE b;
int base;
rb_scan_args(argc, argv, "01", &b);
if (argc == 0) base = 10;
else base = NUM2INT(b);
else {
VALUE b;
rb_scan_args(argc, argv, "01", &b);
base = NUM2INT(b);
}
return rb_big2str(x, base);
}

Просмотреть файл

@ -731,10 +731,12 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
VALUE recur, ary, klass;
st_table *list;
rb_scan_args(argc, argv, "01", &recur);
if (argc == 0) {
recur = Qtrue;
}
else {
rb_scan_args(argc, argv, "01", &recur);
}
klass = CLASS_OF(obj);
list = st_init_numtable();
if (klass && FL_TEST(klass, FL_SINGLETON)) {

3
enum.c
Просмотреть файл

@ -573,12 +573,11 @@ enum_first(int argc, VALUE *argv, VALUE obj)
{
VALUE n, ary[2];
rb_scan_args(argc, argv, "01", &n);
if (argc == 0) {
ary[0] = ary[1] = Qnil;
}
else {
rb_scan_args(argc, argv, "01", &n);
ary[0] = n;
ary[1] = rb_ary_new2(NUM2LONG(n));
}

Просмотреть файл

@ -107,10 +107,12 @@ rb_f_catch(int argc, VALUE *argv)
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *saved_cfp = th->cfp;
rb_scan_args(argc, argv, "01", &tag);
if (argc == 0) {
tag = rb_obj_alloc(rb_cObject);
}
else {
rb_scan_args(argc, argv, "01", &tag);
}
PUSH_TAG();
th->tag->tag = tag;

5
gc.c
Просмотреть файл

@ -1837,9 +1837,12 @@ os_each_obj(int argc, VALUE *argv, VALUE os)
VALUE of;
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &of) == 0) {
if (argc == 0) {
of = 0;
}
else {
rb_scan_args(argc, argv, "01", &of);
}
RETURN_ENUMERATOR(os, 1, &of);
return os_obj_of(of);
}

6
io.c
Просмотреть файл

@ -4642,10 +4642,12 @@ rb_obj_display(int argc, VALUE *argv, VALUE self)
{
VALUE out;
if (rb_scan_args(argc, argv, "01", &out) == 0) {
if (argc == 0) {
out = rb_stdout;
}
else {
rb_scan_args(argc, argv, "01", &out);
}
rb_io_write(out, self);
return Qnil;

Просмотреть файл

@ -1263,7 +1263,7 @@ flo_round(int argc, VALUE *argv, VALUE num)
int ndigits = 0, i;
long val;
if (rb_scan_args(argc, argv, "01", &nd) == 1) {
if (argc > 0 && rb_scan_args(argc, argv, "01", &nd) == 1) {
ndigits = NUM2INT(nd);
}
number = RFLOAT_VALUE(num);
@ -2008,12 +2008,15 @@ rb_fix2str(VALUE x, int base)
static VALUE
fix_to_s(int argc, VALUE *argv, VALUE x)
{
VALUE b;
int base;
rb_scan_args(argc, argv, "01", &b);
if (argc == 0) base = 10;
else base = NUM2INT(b);
else {
VALUE b;
rb_scan_args(argc, argv, "01", &b);
base = NUM2INT(b);
}
return rb_fix2str(x, base);
}

Просмотреть файл

@ -1343,10 +1343,11 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
if (RCLASS_SUPER(klass) != 0) {
rb_raise(rb_eTypeError, "already initialized class");
}
if (rb_scan_args(argc, argv, "01", &super) == 0) {
if (argc == 0) {
super = rb_cObject;
}
else {
rb_scan_args(argc, argv, "01", &super);
rb_check_inheritable(super);
}
RCLASS_SUPER(klass) = super;

Просмотреть файл

@ -756,11 +756,11 @@ proc_wait(int argc, VALUE *argv)
rb_secure(2);
flags = 0;
rb_scan_args(argc, argv, "02", &vpid, &vflags);
if (argc == 0) {
pid = -1;
}
else {
rb_scan_args(argc, argv, "02", &vpid, &vflags);
pid = NUM2PIDT(vpid);
if (argc == 2 && !NIL_P(vflags)) {
flags = NUM2UINT(vflags);
@ -1518,7 +1518,7 @@ rb_f_exit_bang(int argc, VALUE *argv, VALUE obj)
int istatus;
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &status) == 1) {
if (argc > 0 && rb_scan_args(argc, argv, "01", &status) == 1) {
switch (status) {
case Qtrue:
istatus = EXIT_SUCCESS;
@ -1599,7 +1599,7 @@ rb_f_exit(int argc, VALUE *argv)
int istatus;
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &status) == 1) {
if (argc > 0 && rb_scan_args(argc, argv, "01", &status) == 1) {
switch (status) {
case Qtrue:
istatus = EXIT_SUCCESS;

Просмотреть файл

@ -332,9 +332,12 @@ rb_f_srand(int argc, VALUE *argv, VALUE obj)
VALUE seed, old;
rb_secure(4);
if (rb_scan_args(argc, argv, "01", &seed) == 0) {
if (argc == 0) {
seed = random_seed();
}
else {
rb_scan_args(argc, argv, "01", &seed);
}
old = rand_init(seed);
return old;

17
range.c
Просмотреть файл

@ -300,17 +300,20 @@ range_step(int argc, VALUE *argv, VALUE range)
b = RANGE_BEG(range);
e = RANGE_END(range);
if (rb_scan_args(argc, argv, "01", &step) == 0) {
if (argc == 0) {
step = INT2FIX(1);
unit = 1;
}
else if (FIXNUM_P(step)) {
unit = NUM2LONG(step);
}
else {
VALUE tmp = rb_to_int(step);
unit = rb_cmpint(tmp, step, INT2FIX(0));
step = tmp;
rb_scan_args(argc, argv, "01", &step);
if (FIXNUM_P(step)) {
unit = NUM2LONG(step);
}
else {
VALUE tmp = rb_to_int(step);
unit = rb_cmpint(tmp, step, INT2FIX(0));
step = tmp;
}
}
if (unit < 0) {
rb_raise(rb_eArgError, "step can't be negative");

2
re.c
Просмотреть файл

@ -3141,7 +3141,7 @@ rb_reg_s_last_match(int argc, VALUE *argv)
{
VALUE nth;
if (rb_scan_args(argc, argv, "01", &nth) == 1) {
if (argc > 0 && rb_scan_args(argc, argv, "01", &nth) == 1) {
VALUE match = rb_backref_get();
int n;
if (NIL_P(match)) return Qnil;

Просмотреть файл

@ -667,7 +667,7 @@ rb_str_init(int argc, VALUE *argv, VALUE str)
{
VALUE orig;
if (rb_scan_args(argc, argv, "01", &orig) == 1)
if (argc > 0 && rb_scan_args(argc, argv, "01", &orig) == 1)
rb_str_replace(str, orig);
return str;
}
@ -950,7 +950,7 @@ rb_str_format_m(VALUE str, VALUE arg)
return rb_str_format(1, &arg, str);
}
static void
static inline void
str_modifiable(VALUE str)
{
if (FL_TEST(str, STR_TMPLOCK)) {
@ -961,7 +961,7 @@ str_modifiable(VALUE str)
rb_raise(rb_eSecurityError, "Insecure: can't modify string");
}
static int
static inline int
str_independent(VALUE str)
{
str_modifiable(str);
@ -3620,13 +3620,15 @@ rb_str_include(VALUE str, VALUE arg)
static VALUE
rb_str_to_i(int argc, VALUE *argv, VALUE str)
{
VALUE b;
int base;
rb_scan_args(argc, argv, "01", &b);
if (argc == 0) base = 10;
else base = NUM2INT(b);
else {
VALUE b;
rb_scan_args(argc, argv, "01", &b);
base = NUM2INT(b);
}
if (base < 0) {
rb_raise(rb_eArgError, "invalid radix %d", base);
}
@ -5028,9 +5030,12 @@ rb_str_each_line(int argc, VALUE *argv, VALUE str)
VALUE line;
int n;
if (rb_scan_args(argc, argv, "01", &rs) == 0) {
if (argc == 0) {
rs = rb_rs;
}
else {
rb_scan_args(argc, argv, "01", &rs);
}
RETURN_ENUMERATOR(str, argc, argv);
if (NIL_P(rs)) {
rb_yield(str);
@ -5281,7 +5286,7 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
if (len == 0) return Qnil;
p = RSTRING_PTR(str);
e = p + len;
if (rb_scan_args(argc, argv, "01", &rs) == 0) {
if (argc == 0) {
rs = rb_rs;
if (rs == rb_default_rs) {
smart_chomp:
@ -5324,6 +5329,9 @@ rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
return str;
}
}
else {
rb_scan_args(argc, argv, "01", &rs);
}
if (NIL_P(rs)) return Qnil;
StringValue(rs);
rslen = RSTRING_LEN(rs);
@ -5812,11 +5820,13 @@ rb_str_sum(int argc, VALUE *argv, VALUE str)
char *ptr, *p, *pend;
long len;
if (rb_scan_args(argc, argv, "01", &vbits) == 0) {
if (argc == 0) {
bits = 16;
}
else bits = NUM2INT(vbits);
else {
rb_scan_args(argc, argv, "01", &vbits);
bits = NUM2INT(vbits);
}
ptr = p = RSTRING_PTR(str);
len = RSTRING_LEN(str);
pend = p + len;