mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (RESIZE_CAPA): check whether len is longer than capacity.
* array.c (rb_ary_compact_bang): resize ary before changing capacity. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5c9dd204f5
commit
6c4895c78a
2 changed files with 8 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
Wed Oct 15 22:19:14 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* array.c (RESIZE_CAPA): check whether len is longer than capacity.
|
||||
|
||||
* array.c (rb_ary_compact_bang): resize ary before changing capacity.
|
||||
|
||||
Wed Oct 15 16:57:30 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* version.h (RUBY_DESCRIPTION): remove unnecessary space.
|
||||
|
|
3
array.c
3
array.c
|
@ -125,6 +125,7 @@ memfill(register VALUE *mem, register long size, register VALUE val)
|
|||
static void
|
||||
RESIZE_CAPA(VALUE ary, long capacity)
|
||||
{
|
||||
assert(RARRAY_LEN(ary) <= capacity);
|
||||
assert(!OBJ_FROZEN(ary));
|
||||
assert(!ARY_SHARED_P(ary));
|
||||
if (capacity > RARRAY_EMBED_LEN_MAX) {
|
||||
|
@ -2927,10 +2928,10 @@ rb_ary_compact_bang(VALUE ary)
|
|||
if (RARRAY_LEN(ary) == n) {
|
||||
return Qnil;
|
||||
}
|
||||
ARY_SET_LEN(ary, n);
|
||||
if (n * 2 < ARY_CAPA(ary) && ARY_DEFAULT_SIZE * 2 < ARY_CAPA(ary)) {
|
||||
RESIZE_CAPA(ary, n * 2);
|
||||
}
|
||||
ARY_SET_LEN(ary, n);
|
||||
|
||||
return ary;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue