ruby-changes:8516
From: yugui <ko1@a...>
Date: Thu, 30 Oct 2008 02:43:57 +0900 (JST)
Subject: [ruby-changes:8516] Ruby:r20050 (ruby_1_9_1): * array.c (rb_ary_sort_bang): refactoring.
yugui 2008-10-30 02:43:46 +0900 (Thu, 30 Oct 2008) New Revision: 20050 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20050 Log: * array.c (rb_ary_sort_bang): refactoring. Modified files: branches/ruby_1_9_1/array.c Index: ruby_1_9_1/array.c =================================================================== --- ruby_1_9_1/array.c (revision 20049) +++ ruby_1_9_1/array.c (revision 20050) @@ -1751,19 +1751,25 @@ assert(ARY_EMBED_P(tmp)); if (ARY_SHARED_P(ary)) { /* ary might be destructively operated in the given block */ rb_ary_unshare(ary); - FL_SET_EMBED(ary); } + FL_SET_EMBED(ary); MEMCPY(RARRAY_PTR(ary), ARY_EMBED_PTR(tmp), VALUE, ARY_EMBED_LEN(tmp)); ARY_SET_LEN(ary, ARY_EMBED_LEN(tmp)); } else { assert(!ARY_EMBED_P(tmp)); - if (ARY_EMBED_P(ary) || RARRAY_PTR(ary) != RARRAY_PTR(tmp)) { + if (ARY_HEAP_PTR(ary) == ARY_HEAP_PTR(tmp)) { + assert(!ARY_EMBED_P(ary)); + FL_UNSET_SHARED(ary); + ARY_SET_CAPA(ary, ARY_CAPA(tmp)); + } + else { assert(!ARY_SHARED_P(tmp)); if (ARY_EMBED_P(ary)) { FL_UNSET_EMBED(ary); } else if (ARY_SHARED_P(ary)) { + /* ary might be destructively operated in the given block */ rb_ary_unshare(ary); } else { @@ -1773,10 +1779,6 @@ ARY_SET_HEAP_LEN(ary, RARRAY_LEN(tmp)); ARY_SET_CAPA(ary, ARY_CAPA(tmp)); } - else { - FL_UNSET_SHARED(ary); - ARY_SET_CAPA(ary, ARY_CAPA(tmp)); - } /* tmp was lost ownership for the ptr */ FL_UNSET(tmp, FL_FREEZE); FL_SET_EMBED(tmp); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/