mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (rb_ary_flatten_bang): clears temporary array.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f6ac12f7be
commit
0d9c4400fc
2 changed files with 19 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Fri May 8 10:07:02 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c (rb_ary_flatten_bang): clears temporary array.
|
||||||
|
|
||||||
Fri May 8 02:30:14 2009 Akinori MUSHA <knu@iDaemons.org>
|
Fri May 8 02:30:14 2009 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* lib/set.rb (SortedSet#add): Do not require each newly added
|
* lib/set.rb (SortedSet#add): Do not require each newly added
|
||||||
|
|
17
array.c
17
array.c
|
@ -382,10 +382,18 @@ void
|
||||||
rb_ary_free(VALUE ary)
|
rb_ary_free(VALUE ary)
|
||||||
{
|
{
|
||||||
if (ARY_OWNS_HEAP_P(ary)) {
|
if (ARY_OWNS_HEAP_P(ary)) {
|
||||||
xfree(RARRAY_PTR(ary));
|
xfree(ARY_HEAP_PTR(ary));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ary_discard(VALUE ary)
|
||||||
|
{
|
||||||
|
rb_ary_free(ary);
|
||||||
|
RBASIC(ary)->flags |= RARRAY_EMBED_FLAG;
|
||||||
|
RBASIC(ary)->flags &= ~RARRAY_EMBED_LEN_MASK;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ary_make_shared(VALUE ary)
|
ary_make_shared(VALUE ary)
|
||||||
{
|
{
|
||||||
|
@ -3341,8 +3349,13 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary)
|
||||||
if (level == 0) return Qnil;
|
if (level == 0) return Qnil;
|
||||||
|
|
||||||
result = flatten(ary, level, &mod);
|
result = flatten(ary, level, &mod);
|
||||||
if (mod == 0) return Qnil;
|
if (mod == 0) {
|
||||||
|
ary_discard(result);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
if (!(mod = ARY_EMBED_P(result))) rb_obj_freeze(result);
|
||||||
rb_ary_replace(ary, result);
|
rb_ary_replace(ary, result);
|
||||||
|
if (mod) ARY_SET_EMBED_LEN(result, 0);
|
||||||
|
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue