diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-09-24 23:17:42 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-09-24 23:17:42 +0000 |
| commit | 1bcea5e3480f61b495f108860c5c312485accd97 (patch) | |
| tree | 8eab886d4deb3162d13a75f5af803e3b616ff0d1 | |
| parent | b3251c5c391a06832d358af5f59cf2ce4f4aff6a (diff) | |
| download | ruby-1bcea5e3480f61b495f108860c5c312485accd97.tar.gz ruby-1bcea5e3480f61b495f108860c5c312485accd97.tar.xz ruby-1bcea5e3480f61b495f108860c5c312485accd97.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@11016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 8 | ||||
| -rw-r--r-- | array.c | 12 |
2 files changed, 18 insertions, 2 deletions
@@ -1,3 +1,11 @@ +Mon Sep 25 08:14:43 2006 Yukihiro Matsumoto <matz@ruby-lang.org> + + * 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. + Mon Sep 25 08:11:35 2006 Yukihiro Matsumoto <matz@ruby-lang.org> * random.c (rb_f_rand): RDoc typo fix. a patch from Frederick @@ -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; |
