1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (rb_ary_compact_bang): avoid forceful realloc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-05-21 07:50:27 +00:00
parent a5bbd5b8a5
commit f827d95685
2 changed files with 9 additions and 3 deletions

View file

@ -1,3 +1,7 @@
Wed May 21 16:48:22 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_compact_bang): avoid forceful realloc.
Wed May 21 07:42:28 2008 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (rb_usascii_str_new): use rb_str_new.

View file

@ -2710,11 +2710,13 @@ rb_ary_compact_bang(VALUE ary)
if (NIL_P(*t)) t++;
else *p++ = *t++;
}
if (RARRAY_LEN(ary) == (p - RARRAY_PTR(ary))) {
n = p - RARRAY_PTR(ary);
if (RARRAY_LEN(ary) == n) {
return Qnil;
}
n = p - RARRAY_PTR(ary);
RESIZE_CAPA(ary, n);
if (n * 2 < ARY_CAPA(ary) && ARY_DEFAULT_SIZE * 2 < ARY_CAPA(ary)) {
RESIZE_CAPA(ary, ARY_DEFAULT_SIZE * 2);
}
RARRAY(ary)->len = n;
return ary;