Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Unified Diff: src/parser.cc

Issue 39184: Optimizing nested, constant object literals (like JSON objects) by building o... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codegen-ia32.cc ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
===================================================================
--- src/parser.cc (revision 1431)
+++ src/parser.cc (working copy)
@@ -158,10 +158,13 @@
// Decide if a property should be the object boilerplate.
bool IsBoilerplateProperty(ObjectLiteral::Property* property);
- // If the property is CONSTANT type, it returns the literal value,
- // otherwise, it return undefined literal as the placeholder
+ // If the property is CONSTANT type, return the literal value;
+ // if the property is OBJECT_LITERAL and the object literal is
+ // simple return a fixed array containing the keys and values of the
+ // object literal.
+ // Otherwise, it return undefined literal as the placeholder
Mads Ager (chromium) 2009/03/06 09:30:54 it return -> return.
// in the object literal boilerplate.
- Literal* GetBoilerplateValue(ObjectLiteral::Property* property);
+ Handle<Object> GetBoilerplateValue(ObjectLiteral::Property* property);
enum FunctionLiteralType {
EXPRESSION,
@@ -3083,10 +3086,16 @@
}
-Literal* Parser::GetBoilerplateValue(ObjectLiteral::Property* property) {
+Handle<Object> Parser::GetBoilerplateValue(ObjectLiteral::Property* property) {
if (property->kind() == ObjectLiteral::Property::CONSTANT)
- return property->value()->AsLiteral();
- return GetLiteralUndefined();
+ return property->value()->AsLiteral()->handle();
+ if (property->kind() == ObjectLiteral::Property::OBJECT_LITERAL) {
+ ObjectLiteral* object_literal = property->value()->AsObjectLiteral();
+ if (object_literal->is_simple()) {
+ return object_literal->constant_properties();
+ }
+ }
+ return Factory::undefined_value();
}
@@ -3181,24 +3190,30 @@
Handle<FixedArray> constant_properties =
Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED);
int position = 0;
+ bool is_simple = true;
for (int i = 0; i < properties.length(); i++) {
ObjectLiteral::Property* property = properties.at(i);
- if (!IsBoilerplateProperty(property)) continue;
+ if (!IsBoilerplateProperty(property)) {
+ is_simple = false;
+ continue;
+ }
// Add CONSTANT and COMPUTED properties to boilerplate. Use undefined
// value for COMPUTED properties, the real value is filled in at
// runtime. The enumeration order is maintained.
Handle<Object> key = property->key()->handle();
- Literal* literal = GetBoilerplateValue(property);
+ Handle<Object> value = GetBoilerplateValue(property);
+ is_simple = is_simple && !value->IsUndefined();
// Add name, value pair to the fixed array.
constant_properties->set(position++, *key);
- constant_properties->set(position++, *literal->handle());
+ constant_properties->set(position++, *value);
}
return new ObjectLiteral(constant_properties,
properties.elements(),
- literal_index);
+ literal_index,
+ is_simple);
}
« no previous file with comments | « src/codegen-ia32.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698