summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-24 23:17:42 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-09-24 23:17:42 +0000
commitc451d96fe62f1a9549c271aed572682b1b6dbe46 (patch)
tree8eab886d4deb3162d13a75f5af803e3b616ff0d1 /array.c
parent6a7685da36c2e30301680b78ed73b042a4ca12ca (diff)
* array.c (rb_ary_shift): should clear shifting top element.
[ruby-talk:216055] * array.c (rb_ary_shift): avoid creating shared object if array size is small. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/array.c b/array.c
index 6e6778d..6df82f7 100644
--- a/array.c
+++ b/array.c
@@ -501,8 +501,16 @@ rb_ary_shift(ary)
rb_ary_modify_check(ary);
if (RARRAY(ary)->len == 0) return Qnil;
top = RARRAY(ary)->ptr[0];
- ary_make_shared(ary);
- RARRAY(ary)->ptr++; /* shift ptr */
+ if (RARRAY_LEN(ary) < ARY_DEFAULT_SIZE) {
+ MEMMOVE(RARRAY_PTR(ary), RARRAY_PTR(ary)+1, VALUE, RARRAY_LEN(ary));
+ }
+ else {
+ if (!FL_TEST(ary, ELTS_SHARED)) {
+ RARRAY(ary)->ptr[0] = Qnil;
+ }
+ ary_make_shared(ary);
+ RARRAY(ary)->ptr++; /* shift ptr */
+ }
RARRAY(ary)->len--;
return top;