summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-28 07:06:06 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-28 07:06:06 (GMT)
commit1f4efb9aedfb8f537630f7c13e431bb230bebd31 (patch)
treed7216e0981d100da40540800bdd38d6ac7e73a50 /array.c
parent715666cc28d441862778000c56a807c9b4c28d00 (diff)
rest parameter optimization [Feature #15010]
* vm_args.c: rb_ary_dup(args->rest) to be used at most once during parameter setup. [Feature #15010] A patch by chopraanmol1 (Anmol Chopra) <chopraanmol1@gmail.com>. * array.c (rb_ary_behead): added to remove first n elements. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/array.c b/array.c
index c9bf765..3c84a7b 100644
--- a/array.c
+++ b/array.c
@@ -1076,6 +1076,17 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
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:
@@ -1096,7 +1107,7 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
}
ARY_INCREASE_LEN(ary, -n);
- return result;
+ return ary;
}
static VALUE