Reviewers: ulan,
Description:
Force eager compilation of some function literals.
In case a function literal is followed by parenthesis, we consider this
a hint that it will be called immediately. If we happen to have parsed
that function literal eagerly, we can also compile it eagerly.
[email protected]
Please review this at https://chromiumcodereview.appspot.com/10828227/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/ast.h
M src/parser.cc
Index: src/ast.h
diff --git a/src/ast.h b/src/ast.h
index
39756678dc807fb8a8bdd4bd378aebcf1132f7d7..fd96e670b6c2722e5e75d7744fb8bd5723c1fd03
100644
--- a/src/ast.h
+++ b/src/ast.h
@@ -2094,6 +2094,9 @@ class FunctionLiteral: public Expression {
bool is_parenthesized() {
return IsParenthesized::decode(bitfield_) == kIsParenthesized;
}
+ void set_parenthesized() {
+ bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
+ }
int ast_node_count() { return ast_properties_.node_count(); }
AstProperties::Flags* flags() { return ast_properties_.flags(); }
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
b1e2a7c78aa7aa45e8b42baf325e202280e6ab62..fda3200165281ed1e48d21f9aee0fd63b79683d8
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -707,7 +707,7 @@ FunctionLiteral* Parser::ParseLazy() {
if (FLAG_trace_parse && result != NULL) {
double ms = static_cast<double>(OS::Ticks() - start) / 1000;
- SmartArrayPointer<char> name_chars = result->name()->ToCString();
+ SmartArrayPointer<char> name_chars = result->debug_name()->ToCString();
PrintF("[parsing function: %s - took %0.3f ms]\n", *name_chars, ms);
}
return result;
@@ -3450,6 +3450,12 @@ Expression*
Parser::ParseLeftHandSideExpression(bool* ok) {
// should not point to the closing brace otherwise it will
intersect
// with positions recorded for function literal and confuse
debugger.
pos = scanner().peek_location().beg_pos;
+ // Also the trailing parenthesis are a hint that the function
will
+ // be called immediately. If we happen to have parsed a preceding
+ // function literal eagerly, we can also compile it eagerly.
+ if (result->IsFunctionLiteral() && mode() == PARSE_EAGERLY) {
+ result->AsFunctionLiteral()->set_parenthesized();
+ }
}
ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev