* array.c (rb_ary_clear): no need to duplicate buffer just before

clearing.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-07-18 12:20:14 +00:00
parent 25b9eb5e57
commit 10a90fbce8
2 changed files with 10 additions and 2 deletions

View file

@ -2772,9 +2772,12 @@ rb_ary_replace(VALUE copy, VALUE orig)
VALUE
rb_ary_clear(VALUE ary)
{
rb_ary_modify(ary);
rb_ary_modify_check(ary);
ARY_SET_LEN(ary, 0);
if (ARY_DEFAULT_SIZE * 2 < ARY_CAPA(ary)) {
if (ARY_SHARED_P(ary)) {
rb_ary_unshare(ary);
}
else if (ARY_DEFAULT_SIZE * 2 < ARY_CAPA(ary)) {
ary_resize_capa(ary, ARY_DEFAULT_SIZE * 2);
}
return ary;