Properly handle FixedDoubleArrays in sort()
R=jkummerow@chromium.org BUG=91008 TEST=regress-91008.js Review URL: http://codereview.chromium.org/7542008 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8782 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
9226cfe5b7
commit
b333719607
103
src/objects.cc
103
src/objects.cc
@ -10679,19 +10679,19 @@ MaybeObject* JSObject::PrepareElementsForSort(uint32_t limit) {
|
||||
|
||||
set_map(new_map);
|
||||
set_elements(fast_elements);
|
||||
} else {
|
||||
} else if (!HasFastDoubleElements()) {
|
||||
Object* obj;
|
||||
{ MaybeObject* maybe_obj = EnsureWritableFastElements();
|
||||
if (!maybe_obj->ToObject(&obj)) return maybe_obj;
|
||||
}
|
||||
}
|
||||
ASSERT(HasFastElements());
|
||||
ASSERT(HasFastElements() || HasFastDoubleElements());
|
||||
|
||||
// Collect holes at the end, undefined before that and the rest at the
|
||||
// start, and return the number of non-hole, non-undefined values.
|
||||
|
||||
FixedArray* elements = FixedArray::cast(this->elements());
|
||||
uint32_t elements_length = static_cast<uint32_t>(elements->length());
|
||||
FixedArrayBase* elements_base = FixedArrayBase::cast(this->elements());
|
||||
uint32_t elements_length = static_cast<uint32_t>(elements_base->length());
|
||||
if (limit > elements_length) {
|
||||
limit = elements_length ;
|
||||
}
|
||||
@ -10710,47 +10710,78 @@ MaybeObject* JSObject::PrepareElementsForSort(uint32_t limit) {
|
||||
result_double = HeapNumber::cast(new_double);
|
||||
}
|
||||
|
||||
AssertNoAllocation no_alloc;
|
||||
|
||||
// Split elements into defined, undefined and the_hole, in that order.
|
||||
// Only count locations for undefined and the hole, and fill them afterwards.
|
||||
WriteBarrierMode write_barrier = elements->GetWriteBarrierMode(no_alloc);
|
||||
unsigned int undefs = limit;
|
||||
unsigned int holes = limit;
|
||||
// Assume most arrays contain no holes and undefined values, so minimize the
|
||||
// number of stores of non-undefined, non-the-hole values.
|
||||
for (unsigned int i = 0; i < undefs; i++) {
|
||||
Object* current = elements->get(i);
|
||||
if (current->IsTheHole()) {
|
||||
holes--;
|
||||
undefs--;
|
||||
} else if (current->IsUndefined()) {
|
||||
undefs--;
|
||||
} else {
|
||||
continue;
|
||||
uint32_t result = 0;
|
||||
if (elements_base->map() == heap->fixed_double_array_map()) {
|
||||
FixedDoubleArray* elements = FixedDoubleArray::cast(elements_base);
|
||||
// Split elements into defined and the_hole, in that order.
|
||||
unsigned int holes = limit;
|
||||
// Assume most arrays contain no holes and undefined values, so minimize the
|
||||
// number of stores of non-undefined, non-the-hole values.
|
||||
for (unsigned int i = 0; i < holes; i++) {
|
||||
if (elements->is_the_hole(i)) {
|
||||
holes--;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
// Position i needs to be filled.
|
||||
while (holes > i) {
|
||||
if (elements->is_the_hole(holes)) {
|
||||
holes--;
|
||||
} else {
|
||||
elements->set(i, elements->get(holes));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Position i needs to be filled.
|
||||
while (undefs > i) {
|
||||
current = elements->get(undefs);
|
||||
result = holes;
|
||||
while (holes < limit) {
|
||||
elements->set_the_hole(holes);
|
||||
holes++;
|
||||
}
|
||||
} else {
|
||||
FixedArray* elements = FixedArray::cast(elements_base);
|
||||
AssertNoAllocation no_alloc;
|
||||
|
||||
// Split elements into defined, undefined and the_hole, in that order. Only
|
||||
// count locations for undefined and the hole, and fill them afterwards.
|
||||
WriteBarrierMode write_barrier = elements->GetWriteBarrierMode(no_alloc);
|
||||
unsigned int undefs = limit;
|
||||
unsigned int holes = limit;
|
||||
// Assume most arrays contain no holes and undefined values, so minimize the
|
||||
// number of stores of non-undefined, non-the-hole values.
|
||||
for (unsigned int i = 0; i < undefs; i++) {
|
||||
Object* current = elements->get(i);
|
||||
if (current->IsTheHole()) {
|
||||
holes--;
|
||||
undefs--;
|
||||
} else if (current->IsUndefined()) {
|
||||
undefs--;
|
||||
} else {
|
||||
elements->set(i, current, write_barrier);
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
// Position i needs to be filled.
|
||||
while (undefs > i) {
|
||||
current = elements->get(undefs);
|
||||
if (current->IsTheHole()) {
|
||||
holes--;
|
||||
undefs--;
|
||||
} else if (current->IsUndefined()) {
|
||||
undefs--;
|
||||
} else {
|
||||
elements->set(i, current, write_barrier);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
uint32_t result = undefs;
|
||||
while (undefs < holes) {
|
||||
elements->set_undefined(undefs);
|
||||
undefs++;
|
||||
}
|
||||
while (holes < limit) {
|
||||
elements->set_the_hole(holes);
|
||||
holes++;
|
||||
result = undefs;
|
||||
while (undefs < holes) {
|
||||
elements->set_undefined(undefs);
|
||||
undefs++;
|
||||
}
|
||||
while (holes < limit) {
|
||||
elements->set_the_hole(holes);
|
||||
holes++;
|
||||
}
|
||||
}
|
||||
|
||||
if (result <= static_cast<uint32_t>(Smi::kMaxValue)) {
|
||||
|
43
test/mjsunit/regress/regress-91008.js
Normal file
43
test/mjsunit/regress/regress-91008.js
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2010 the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
function testsort(n) {
|
||||
var numbers=new Array(n);
|
||||
for (var i=0;i<n;i++) numbers[i]=i;
|
||||
delete numbers[50];
|
||||
delete numbers[150];
|
||||
delete numbers[25000];
|
||||
delete numbers[n-1];
|
||||
delete numbers[n-2];
|
||||
delete numbers[30];
|
||||
delete numbers[2];
|
||||
delete numbers[1];
|
||||
delete numbers[0];
|
||||
numbers.sort();
|
||||
}
|
||||
|
||||
testsort(100000)
|
Loading…
Reference in New Issue
Block a user