summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-21 07:50:27 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-21 07:50:27 +0000
commitb295753888d25365090c4e8e0385c84103e67e85 (patch)
tree47280358e5e58fe0ce2588b5f4f27becb46a8ffe
parentef65008a672eaa7eed19c5fcb28b087766b4defc (diff)
downloadruby-b295753888d25365090c4e8e0385c84103e67e85.tar.gz
ruby-b295753888d25365090c4e8e0385c84103e67e85.tar.xz
ruby-b295753888d25365090c4e8e0385c84103e67e85.zip
* array.c (rb_ary_compact_bang): avoid forceful realloc.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--array.c8
2 files changed, 9 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 30cab8267..c0905e83f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/array.c b/array.c
index 6fd7a75e0..f42eb9f82 100644
--- a/array.c
+++ b/array.c
@@ -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;