summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-03 02:27:50 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-03 02:27:50 +0000
commit574422733dd11b242ba04c02579710e42fa58a77 (patch)
treea9c92e59c4b7b8b730f1e789b59e98a173fd1b5d /array.c
parenta84bfcbf0061d30946e4d9692e9d4fa70682aef4 (diff)
* array.c: Improve performance of Array#shift. use shared instead of
MEMMOVE if with arguments. Patch by @ksss [fix GH-537] * test/ruby/test_array.rb: ditto. * benchmark/bm_array_shift.rb: Added benchmark of GH-537 issue. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/array.c b/array.c
index 6babe97..08958ae 100644
--- a/array.c
+++ b/array.c
@@ -1066,14 +1066,21 @@ rb_ary_shift_m(int argc, VALUE *argv, VALUE ary)
n = RARRAY_LEN(result);
if (ARY_SHARED_P(ary)) {
if (ARY_SHARED_OCCUPIED(ARY_SHARED(ary))) {
+ setup_occupied_shared:
ary_mem_clear(ary, 0, n);
}
ARY_INCREASE_PTR(ary, n);
}
else {
- RARRAY_PTR_USE(ary, ptr, {
- MEMMOVE(ptr, ptr + n, VALUE, RARRAY_LEN(ary)-n);
- }); /* WB: no new reference */
+ if (RARRAY_LEN(ary) < ARY_DEFAULT_SIZE) {
+ RARRAY_PTR_USE(ary, ptr, {
+ MEMMOVE(ptr, ptr+n, VALUE, RARRAY_LEN(ary)-n);
+ }); /* WB: no new reference */
+ }
+ else {
+ ary_make_shared(ary);
+ goto setup_occupied_shared;
+ }
}
ARY_INCREASE_LEN(ary, -n);