Skip to content

Commit

Permalink
* numeric.c (fix_to_s): avoid rb_scan_args() when no argument
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
matz committed Mar 5, 2008
1 parent 413db1b commit 39787ea
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 54 deletions.
21 changes: 21 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
Wed Mar 5 14:00:49 2008 Yukihiro Matsumoto <[email protected]>

* 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 <[email protected]>

* lib/debug.rb: require 'continuation' to implement "restart"
Expand Down
32 changes: 16 additions & 16 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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])))
Expand All @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 1 addition & 2 deletions enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 3 additions & 1 deletion eval_jump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 7 additions & 4 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions range.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion re.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 39787ea

Please sign in to comment.