Project

General

Profile

Feature #15010 ยป Reduce-allocation-for-rest-parameters-v2.patch

Patch 2 - chopraanmol1 (Anmol Chopra), 08/21/2018 07:34 AM

View differences:

array.c
1076 1076
    rb_ary_modify_check(ary);
1077 1077
    result = ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST);
1078 1078
    n = RARRAY_LEN(result);
1079
    rb_ary_behead(ary,n);
1080

  
1081
    return result;
1082
}
1083

  
1084
MJIT_FUNC_EXPORTED VALUE
1085
rb_ary_behead(VALUE ary, long n)
1086
{
1087
    if(n<=0) return ary;
1088

  
1089
    rb_ary_modify_check(ary);
1079 1090
    if (ARY_SHARED_P(ary)) {
1080 1091
	if (ARY_SHARED_OCCUPIED(ARY_SHARED(ary))) {
1081 1092
	  setup_occupied_shared:
......
1096 1107
    }
1097 1108
    ARY_INCREASE_LEN(ary, -n);
1098 1109

  
1099
    return result;
1110
    return ary;
1100 1111
}
1101 1112

  
1102 1113
static VALUE
internal.h
1087 1087
VALUE rb_to_array_type(VALUE obj);
1088 1088
VALUE rb_check_to_array(VALUE ary);
1089 1089
VALUE rb_ary_tmp_new_from_values(VALUE, long, const VALUE *);
1090
VALUE rb_ary_behead(VALUE, long);
1090 1091
#if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
1091 1092
#define rb_ary_new_from_args(n, ...) \
1092 1093
    __extension__ ({ \
vm_args.c
162 162
    VALUE ary;
163 163

  
164 164
    if (args->rest) {
165
	ary = rb_ary_subseq(args->rest, args->rest_index, RARRAY_LEN(args->rest) - args->rest_index);
165
        ary = rb_ary_behead(args->rest, args->rest_index);
166
        args->rest_index = 0;
166 167
	args->rest = 0;
167 168
    }
168 169
    else {
......
301 302
args_setup_post_parameters(struct args_info *args, int argc, VALUE *locals)
302 303
{
303 304
    long len;
304
    args_copy(args);
305 305
    len = RARRAY_LEN(args->rest);
306 306
    MEMCPY(locals, RARRAY_CONST_PTR(args->rest) + len - argc, VALUE, argc);
307 307
    rb_ary_resize(args->rest, len - argc);
......
343 343
static inline void
344 344
args_setup_rest_parameter(struct args_info *args, VALUE *locals)
345 345
{
346
    args_copy(args);
347 346
    *locals = args_rest_array(args);
348 347
}
349 348

  
......
561 560
    }
562 561

  
563 562
    if (ci->flag & VM_CALL_ARGS_SPLAT) {
564
	args->rest = locals[--args->argc];
565
	args->rest_index = 0;
566
	given_argc += RARRAY_LENINT(args->rest) - 1;
563
        VALUE rest = locals[--args->argc];
564
        long len = RARRAY_LEN(rest);
565
        MEMCPY(args->argv + args->argc, RARRAY_CONST_PTR(rest), VALUE, len);
566
        args->argc += len;
567
        given_argc += len - 1;
568
        args->rest = Qfalse;
567 569
    }
568 570
    else {
569 571
	args->rest = Qfalse;
......
628 630
	args_setup_lead_parameters(args, iseq->body->param.lead_num, locals + 0);
629 631
    }
630 632

  
633
    if (iseq->body->param.flags.has_rest || iseq->body->param.flags.has_post){
634
        args_copy(args);
635
    }
636

  
631 637
    if (iseq->body->param.flags.has_post) {
632 638
	args_setup_post_parameters(args, iseq->body->param.post_num, locals + iseq->body->param.post_start);
633 639
    }