Commit 7256d90a authored by verwaest's avatar verwaest Committed by Commit bot

[ignition] Prefill the constant array with holes to avoid needing to write padding holes

BUG=

Review-Url: https://codereview.chromium.org/2586513002
Cr-Commit-Position: refs/heads/master@{#42139}
parent 09167bf6
...@@ -132,13 +132,10 @@ Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) { ...@@ -132,13 +132,10 @@ Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) {
handle(reserved_smi.first, isolate)); handle(reserved_smi.first, isolate));
} }
Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArray( Handle<FixedArray> fixed_array = isolate->factory()->NewFixedArrayWithHoles(
static_cast<int>(size()), PretenureFlag::TENURED); static_cast<int>(size()), PretenureFlag::TENURED);
int array_index = 0; int array_index = 0;
for (const ConstantArraySlice* slice : idx_slice_) { for (const ConstantArraySlice* slice : idx_slice_) {
if (array_index == fixed_array->length()) {
break;
}
DCHECK(array_index == 0 || DCHECK(array_index == 0 ||
base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index))); base::bits::IsPowerOfTwo32(static_cast<uint32_t>(array_index)));
#if DEBUG #if DEBUG
...@@ -151,15 +148,14 @@ Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) { ...@@ -151,15 +148,14 @@ Handle<FixedArray> ConstantArrayBuilder::ToFixedArray(Isolate* isolate) {
for (size_t i = 0; i < slice->size(); ++i) { for (size_t i = 0; i < slice->size(); ++i) {
fixed_array->set(array_index++, *slice->At(slice->start_index() + i)); fixed_array->set(array_index++, *slice->At(slice->start_index() + i));
} }
// Insert holes where reservations led to unused slots. // Leave holes where reservations led to unused slots.
size_t padding = size_t padding = slice->capacity() - slice->size();
std::min(static_cast<size_t>(fixed_array->length() - array_index), if (static_cast<size_t>(fixed_array->length() - array_index) <= padding) {
slice->capacity() - slice->size()); break;
for (size_t i = 0; i < padding; i++) {
fixed_array->set(array_index++, *the_hole_value());
} }
array_index += padding;
} }
DCHECK_EQ(array_index, fixed_array->length()); DCHECK_GE(array_index, fixed_array->length());
return fixed_array; return fixed_array;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment