Chromium Code Reviews| Index: src/ast/ast.cc |
| diff --git a/src/ast/ast.cc b/src/ast/ast.cc |
| index 530bd50aaf7e12fadf6860b241663b594c5c514c..9a4a68b14d472b40187d1cd6ba173d0cb8fc5309 100644 |
| --- a/src/ast/ast.cc |
| +++ b/src/ast/ast.cc |
| @@ -580,11 +580,9 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) { |
| if (!constant_elements_.is_null()) return; |
| int constants_length = values()->length(); |
| - |
| - // Allocate a fixed array to hold all the object literals. |
| - Handle<JSArray> array = isolate->factory()->NewJSArray( |
| - FAST_HOLEY_SMI_ELEMENTS, constants_length, constants_length, |
| - INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| + ElementsKind kind = FAST_SMI_ELEMENTS; |
|
Toon Verwaest
2016/11/08 10:18:02
FIRST_FAST_ELEMENTS_KIND?
Yang
2016/11/09 07:32:23
Done.
|
| + Handle<FixedArray> fixed_array = |
| + isolate->factory()->NewFixedArrayWithHoles(constants_length); |
| // Fill in the literals. |
| bool is_simple = true; |
| @@ -615,29 +613,44 @@ void ArrayLiteral::BuildConstantElements(Isolate* isolate) { |
| is_simple = false; |
| } |
| - JSObject::AddDataElement(array, array_index, boilerplate_value, NONE) |
| - .Assert(); |
| + kind = GetMoreGeneralElementsKind(kind, |
| + boilerplate_value->OptimalElementsKind()); |
| + fixed_array->set(array_index, *boilerplate_value); |
| } |
| - JSObject::ValidateElements(array); |
| - Handle<FixedArrayBase> element_values(array->elements()); |
| - |
| // Simple and shallow arrays can be lazily copied, we transform the |
| // elements array to a copy-on-write array. |
| if (is_simple && depth_acc == 1 && array_index > 0 && |
| - array->HasFastSmiOrObjectElements()) { |
| - element_values->set_map(isolate->heap()->fixed_cow_array_map()); |
| + IsFastSmiOrObjectElementsKind(kind)) { |
| + fixed_array->set_map(isolate->heap()->fixed_cow_array_map()); |
| + } |
| + |
| + Handle<FixedArrayBase> elements = fixed_array; |
| + |
| + // In case of only double elements, copy over into a FixedDoubleArray. |
| + if (IsFastDoubleElementsKind(kind)) { |
| + Handle<FixedDoubleArray> fixed_double_array = |
| + Handle<FixedDoubleArray>::cast( |
| + isolate->factory()->NewFixedDoubleArray(constants_length)); |
| + for (int i = 0; i < constants_length; i++) { |
| + Object* element = fixed_array->get(i); |
| + if (element->IsTheHole(isolate)) { |
| + DCHECK(is_holey); |
| + fixed_double_array->set_the_hole(i); |
| + } else { |
| + fixed_double_array->set(i, element->Number()); |
|
Toon Verwaest
2016/11/08 10:16:54
What about having a CopyElements on the elements a
Yang
2016/11/09 07:32:23
Done.
|
| + } |
| + } |
| + elements = fixed_double_array; |
| } |
| + if (is_holey) kind = GetHoleyElementsKind(kind); |
| + |
| // Remember both the literal's constant values as well as the ElementsKind |
| // in a 2-element FixedArray. |
| Handle<FixedArray> literals = isolate->factory()->NewFixedArray(2, TENURED); |
| - |
| - ElementsKind kind = array->GetElementsKind(); |
| - kind = is_holey ? GetHoleyElementsKind(kind) : GetPackedElementsKind(kind); |
| - |
| literals->set(0, Smi::FromInt(kind)); |
| - literals->set(1, *element_values); |
| + literals->set(1, *elements); |
| constant_elements_ = literals; |
| set_is_simple(is_simple); |