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
rb_ary_modify_check(ary);
result = ary_take_first_or_last(argc, argv, ary, ARY_TAKE_FIRST);
n = RARRAY_LEN(result);
rb_ary_behead(ary,n);
return result;
}
MJIT_FUNC_EXPORTED VALUE
rb_ary_behead(VALUE ary, long n)
{
if(n<=0) return ary;
rb_ary_modify_check(ary);
if (ARY_SHARED_P(ary)) {
if (ARY_SHARED_OCCUPIED(ARY_SHARED(ary))) {
setup_occupied_shared:
......
}
ARY_INCREASE_LEN(ary, -n);
return result;
return ary;
}
static VALUE
internal.h
VALUE rb_to_array_type(VALUE obj);
VALUE rb_check_to_array(VALUE ary);
VALUE rb_ary_tmp_new_from_values(VALUE, long, const VALUE *);
VALUE rb_ary_behead(VALUE, long);
#if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO)
#define rb_ary_new_from_args(n, ...) \
__extension__ ({ \
vm_args.c
VALUE ary;
if (args->rest) {
ary = rb_ary_subseq(args->rest, args->rest_index, RARRAY_LEN(args->rest) - args->rest_index);
ary = rb_ary_behead(args->rest, args->rest_index);
args->rest_index = 0;
args->rest = 0;
}
else {
......
args_setup_post_parameters(struct args_info *args, int argc, VALUE *locals)
{
long len;
args_copy(args);
len = RARRAY_LEN(args->rest);
MEMCPY(locals, RARRAY_CONST_PTR(args->rest) + len - argc, VALUE, argc);
rb_ary_resize(args->rest, len - argc);
......
static inline void
args_setup_rest_parameter(struct args_info *args, VALUE *locals)
{
args_copy(args);
*locals = args_rest_array(args);
}
......
}
if (ci->flag & VM_CALL_ARGS_SPLAT) {
args->rest = locals[--args->argc];
args->rest_index = 0;
given_argc += RARRAY_LENINT(args->rest) - 1;
VALUE rest = locals[--args->argc];
long len = RARRAY_LEN(rest);
MEMCPY(args->argv + args->argc, RARRAY_CONST_PTR(rest), VALUE, len);
args->argc += len;
given_argc += len - 1;
args->rest = Qfalse;
}
else {
args->rest = Qfalse;
......
args_setup_lead_parameters(args, iseq->body->param.lead_num, locals + 0);
}
if (iseq->body->param.flags.has_rest || iseq->body->param.flags.has_post){
args_copy(args);
}
if (iseq->body->param.flags.has_post) {
args_setup_post_parameters(args, iseq->body->param.post_num, locals + iseq->body->param.post_start);
}
(2-2/4)