Revision: 12320
Author:   [email protected]
Date:     Thu Aug 16 04:54:48 2012
Log:      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]

Review URL: https://chromiumcodereview.appspot.com/10828227
http://code.google.com/p/v8/source/detail?r=12320

Modified:
 /branches/bleeding_edge/src/ast.h
 /branches/bleeding_edge/src/parser.cc

=======================================
--- /branches/bleeding_edge/src/ast.h   Tue Aug  7 07:47:36 2012
+++ /branches/bleeding_edge/src/ast.h   Thu Aug 16 04:54:48 2012
@@ -2091,9 +2091,17 @@

bool is_function() { return IsFunction::decode(bitfield_) == kIsFunction; }

+  // This is used as a heuristic on when to eagerly compile a function
+  // literal. We consider the following constructs as hints that the
+  // function will be called immediately:
+  // - (function() { ... })();
+  // - var x = function() { ... }();
   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(); }
=======================================
--- /branches/bleeding_edge/src/parser.cc       Tue Aug 14 03:06:34 2012
+++ /branches/bleeding_edge/src/parser.cc       Thu Aug 16 04:54:48 2012
@@ -707,7 +707,7 @@

   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 @@
// 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

Reply via email to