From c03c71a937601f71cd9480b1887b600e86732502 Mon Sep 17 00:00:00 2001 From: "fschneider@chromium.org" Date: Wed, 15 Dec 2010 16:12:55 +0000 Subject: [PATCH] Emit a load of the elements array only before the first store. This avoid emitting the load for empty and constant array literals. Review URL: http://codereview.chromium.org/5697006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6034 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 05a59d2..635678b 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -3023,7 +3023,8 @@ void HGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { // The array is expected in the bailout environment during computation // of the property values and is the value of the entire expression. PushAndAdd(literal); - HValue* elements = AddInstruction(new HLoadElements(literal)); + + HLoadElements* elements = NULL; for (int i = 0; i < length; i++) { Expression* subexpr = subexprs->at(i); @@ -3034,6 +3035,13 @@ void HGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { VISIT_FOR_VALUE(subexpr); HValue* value = Pop(); if (!Smi::IsValid(i)) BAILOUT("Non-smi key in array literal"); + + // Load the elements array before the first store. + if (elements == NULL) { + elements = new HLoadElements(literal); + AddInstruction(elements); + } + HValue* key = AddInstruction(new HConstant(Handle(Smi::FromInt(i)), Representation::Integer32())); AddInstruction(new HStoreKeyedFastElement(elements, key, value)); -- 2.7.4