Reviewers: Kasper Lund,

Description:
Make preparsing data reusable.
Fix bug in writing symbol ids over 128.

Please review this at http://codereview.chromium.org/3416010/show

Affected files:
  M src/parser.h
  M src/parser.cc


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 856c474066191acc0691432f9eecabf67a19e499..a29339b46669f3e4ed888e4a16ce8d03301c069f 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1001,7 +1001,7 @@ class CompleteParserRecorder: public PartialParserRecorder { Vector<Vector<const char> > symbol = symbol_entries_.AddBlock(1, literal);
       entry->key = &symbol[0];
     }
-    symbol_store_.Add(id - 1);
+    WriteNumber(id - 1);
   }

   virtual Vector<unsigned> ExtractData() {
@@ -1503,6 +1503,8 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
   source->TryFlatten();
   scanner_.Initialize(source, JAVASCRIPT);
   ASSERT(target_stack_ == NULL);
+  if (pre_data_ != NULL) pre_data_->Initialize();
+

   // Compute the parsing mode.
   mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
@@ -5492,7 +5494,9 @@ ScriptDataImpl* PartialPreParse(Handle<String> source,


 void ScriptDataImpl::Initialize() {
+  // Resets pointers to initial value, if reusing a pre-used ScriptData.
   if (store_.length() >= kHeaderSize) {
+    function_index_ = kHeaderSize;
     int symbol_data_offset = kHeaderSize + store_[kFunctionsSizeOffset];
     if (store_.length() > symbol_data_offset) {
       symbol_data_ = reinterpret_cast<byte*>(&store_[symbol_data_offset]);
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index 8bab92d5a923c0833d4af3bec86c0adede5458b0..8c00857276388d3640e2e217d5c99f18f51f6f2d 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -101,10 +101,7 @@ class ScriptDataImpl : public ScriptData {
  public:
   explicit ScriptDataImpl(Vector<unsigned> store)
       : store_(store),
-        function_index_(kHeaderSize),
-        owns_store_(true) {
-    Initialize();
-  }
+        owns_store_(true) { }

   // Create an empty ScriptDataImpl that is guaranteed to not satisfy
   // a SanityCheck.
@@ -190,10 +187,8 @@ class ScriptDataImpl : public ScriptData {
   ScriptDataImpl(const char* backing_store, int length)
: store_(reinterpret_cast<unsigned*>(const_cast<char*>(backing_store)),
                length / sizeof(unsigned)),
-        function_index_(kHeaderSize),
         owns_store_(false) {
ASSERT_EQ(0, reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned));
-    Initialize();
   }

   // Read strings written by ParserRecorder::WriteString.


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to