Project

General

Profile

Feature #12333 ยป fixed_multi_concat_prepend.patch

spinute (Satoru Horie), 05/03/2016 08:03 AM

View differences:

array.c
3620 3620

  
3621 3621
/*
3622 3622
 *  call-seq:
3623
 *     ary.concat(other_ary)   -> ary
3623
 *     ary.concat(other_ary1, other_ary2,...)   -> ary
3624 3624
 *
3625
 *  Appends the elements of +other_ary+ to +self+.
3625
 *  Appends the elements of +other_ary+s to +self+.
3626 3626
 *
3627 3627
 *     [ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
3628
 *     [ "a" ].concat( ["b"], ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
3629
 *     [ "a" ].concat #=> [ "a" ]
3630
 *
3628 3631
 *     a = [ 1, 2, 3 ]
3629 3632
 *     a.concat( [ 4, 5 ] )
3630 3633
 *     a                                 #=> [ 1, 2, 3, 4, 5 ]
3631 3634
 *
3635
 *     a = [ 1, 2 ]
3636
 *     a.concat(a, a)                    #=> [1, 2, 1, 2, 1, 2]
3637
 *
3632 3638
 *  See also Array#+.
3633 3639
 */
3634 3640

  
......
3643 3649
    return x;
3644 3650
}
3645 3651

  
3652
static VALUE
3653
rb_ary_concat_m(int argc, VALUE *argv, VALUE ary)
3654
{
3655
	VALUE args = rb_ary_new();
3656

  
3657
	for (int i = 0; i < argc; i++)
3658
		rb_ary_concat(args, argv[i]);
3659

  
3660
	rb_ary_concat(ary, args);
3661

  
3662
	return ary;
3663
}
3664

  
3646 3665

  
3647 3666
/*
3648 3667
 *  call-seq:
......
5810 5829
    rb_define_method(rb_cArray, "fetch", rb_ary_fetch, -1);
5811 5830
    rb_define_method(rb_cArray, "first", rb_ary_first, -1);
5812 5831
    rb_define_method(rb_cArray, "last", rb_ary_last, -1);
5813
    rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
5832
    rb_define_method(rb_cArray, "concat", rb_ary_concat_m, -1);
5814 5833
    rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
5815 5834
    rb_define_method(rb_cArray, "push", rb_ary_push_m, -1);
5816 5835
    rb_define_method(rb_cArray, "pop", rb_ary_pop_m, -1);
string.c
2766 2766
    return str1;
2767 2767
}
2768 2768

  
2769
static VALUE
2770
rb_str_concat_m(int argc, VALUE *argv, VALUE str)
2771
{
2772
	VALUE args = rb_str_new(0, 0);
2773

  
2774
	for (int i = 0; i < argc; i++)
2775
		rb_str_concat(args, argv[i]);
2776

  
2777
	rb_str_concat(str, args);
2778

  
2779
	return str;
2780
}
2781

  
2769 2782
/*
2770 2783
 *  call-seq:
2771 2784
 *     str.prepend(other_str)  -> str
......
2786 2799
    return str;
2787 2800
}
2788 2801

  
2802
static VALUE
2803
rb_str_prepend_m(int argc, VALUE *argv, VALUE str)
2804
{
2805
	VALUE args = rb_str_new(0, 0);
2806

  
2807
	for (int i = 0; i < argc; i++)
2808
		rb_str_concat(args, argv[i]);
2809

  
2810
	rb_str_prepend(str, args);
2811

  
2812
	return str;
2813
}
2814

  
2789 2815
st_index_t
2790 2816
rb_str_hash(VALUE str)
2791 2817
{
......
9681 9707
    rb_define_method(rb_cString, "codepoints", rb_str_codepoints, 0);
9682 9708
    rb_define_method(rb_cString, "reverse", rb_str_reverse, 0);
9683 9709
    rb_define_method(rb_cString, "reverse!", rb_str_reverse_bang, 0);
9684
    rb_define_method(rb_cString, "concat", rb_str_concat, 1);
9710
    rb_define_method(rb_cString, "concat", rb_str_concat_m, -1);
9685 9711
    rb_define_method(rb_cString, "<<", rb_str_concat, 1);
9686
    rb_define_method(rb_cString, "prepend", rb_str_prepend, 1);
9712
    rb_define_method(rb_cString, "prepend", rb_str_prepend_m, -1);
9687 9713
    rb_define_method(rb_cString, "crypt", rb_str_crypt, 1);
9688 9714
    rb_define_method(rb_cString, "intern", rb_str_intern, 0); /* in symbol.c */
9689 9715
    rb_define_method(rb_cString, "to_sym", rb_str_intern, 0); /* in symbol.c */