Revision: 20007
Author:   [email protected]
Date:     Mon Mar 17 15:57:19 2014 UTC
Log:      Experimental parser: small fixes

[email protected]

BUG=

Review URL: https://codereview.chromium.org/201953002
http://code.google.com/p/v8/source/detail?r=20007

Modified:
 /branches/experimental/parser/src/factory.cc
 /branches/experimental/parser/src/factory.h
 /branches/experimental/parser/src/heap.cc
 /branches/experimental/parser/src/heap.h
 /branches/experimental/parser/src/lexer/lexer-shell.cc
 /branches/experimental/parser/src/lexer/lexer.cc

=======================================
--- /branches/experimental/parser/src/factory.cc Fri Mar 14 20:00:50 2014 UTC +++ /branches/experimental/parser/src/factory.cc Mon Mar 17 15:57:19 2014 UTC
@@ -272,10 +272,12 @@


 Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
+                                             bool check_for_one_byte,
                                              PretenureFlag pretenure) {
   CALL_HEAP_FUNCTION(
       isolate(),
-      isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
+      isolate()->heap()->AllocateStringFromTwoByte(
+          string, check_for_one_byte, pretenure),
       String);
 }

=======================================
--- /branches/experimental/parser/src/factory.h Fri Mar 14 20:00:50 2014 UTC
+++ /branches/experimental/parser/src/factory.h Mon Mar 17 15:57:19 2014 UTC
@@ -149,6 +149,7 @@

   Handle<String> NewStringFromTwoByte(
       Vector<const uc16> str,
+      bool check_for_one_byte = true,
       PretenureFlag pretenure = NOT_TENURED);

   // Allocates and partially initializes an ASCII or TwoByte String. The
=======================================
--- /branches/experimental/parser/src/heap.cc   Fri Mar 14 20:00:50 2014 UTC
+++ /branches/experimental/parser/src/heap.cc   Mon Mar 17 15:57:19 2014 UTC
@@ -4811,13 +4811,14 @@


 MaybeObject* Heap::AllocateStringFromTwoByte(Vector<const uc16> string,
+                                             bool check_for_one_byte,
                                              PretenureFlag pretenure) {
   // Check if the string is an ASCII string.
   Object* result;
   int length = string.length();
   const uc16* start = string.start();

-  if (String::IsOneByte(start, length)) {
+  if (check_for_one_byte && String::IsOneByte(start, length)) {
MaybeObject* maybe_result = AllocateRawOneByteString(length, pretenure);
     if (!maybe_result->ToObject(&result)) return maybe_result;
     CopyChars(SeqOneByteString::cast(result)->GetChars(), start, length);
=======================================
--- /branches/experimental/parser/src/heap.h    Fri Mar 14 20:00:50 2014 UTC
+++ /branches/experimental/parser/src/heap.h    Mon Mar 17 15:57:19 2014 UTC
@@ -868,6 +868,7 @@
       PretenureFlag pretenure = NOT_TENURED);
   MUST_USE_RESULT MaybeObject* AllocateStringFromTwoByte(
       Vector<const uc16> str,
+      bool check_for_one_byte,
       PretenureFlag pretenure = NOT_TENURED);

   // Allocates an internalized string in old space based on the character
=======================================
--- /branches/experimental/parser/src/lexer/lexer-shell.cc Mon Mar 17 14:04:22 2014 UTC +++ /branches/experimental/parser/src/lexer/lexer-shell.cc Mon Mar 17 15:57:19 2014 UTC
@@ -96,11 +96,11 @@
       if (c <= unibrow::Utf8::kMaxOneByteChar) {
         position++;
       } else {
-        *is_one_byte = false;
         c =  unibrow::Utf8::CalculateValue(char_data + position,
                                            file_size - position,
                                            &position);
       }
+      if (c > unibrow::Latin1::kMaxChar) *is_one_byte = false;
       if (c > kMaxUtf16Character) {
         utf16_chars += 2;
       } else {
@@ -222,32 +222,10 @@
          token == Token::STRING ||
          token == Token::NUMBER;
 }
-
-
-template<typename Char>
-static void Copy(const Vector<Char>& literal,
-                 SmartArrayPointer<const uint16_t>* result,
-                 int* literal_length) {
-  uint16_t* data = new uint16_t[literal.length()];
-  result->Reset(data);
-  for (int i = 0; i < literal.length(); i++) {
-    data[i] = literal[i];
-  }
-  *literal_length = literal.length();
-}


 class TokenWithLocation {
  public:
-  Token::Value value;
-  int beg;
-  int end;
-  bool is_one_byte;
-  SmartArrayPointer<const uint16_t> literal;
-  int literal_length;
-  // The location of the latest octal position when the token was seen.
-  int octal_beg;
-  int octal_end;
   TokenWithLocation(Token::Value token,
                     Scanner* scanner,
                     Handle<String> literal_string)
@@ -261,10 +239,15 @@
     if (!literal_string.is_null()) {
       DisallowHeapAllocation no_alloc;
       String::FlatContent content = literal_string->GetFlatContent();
+      literal_length = literal_string->length();
+      literal.Reset(new uint16_t[literal_length]);
       if (content.IsAscii()) {
-        Copy(content.ToOneByteVector(), &literal, &literal_length);
+        is_one_byte = true;
+        CopyChars(
+ literal.get(), content.ToOneByteVector().start(), literal_length);
       } else {
-        Copy(content.ToUC16Vector(), &literal, &literal_length);
+        CopyChars(
+          literal.get(), content.ToUC16Vector().start(), literal_length);
       }
     }
   }
@@ -274,7 +257,7 @@
       return;
     }
     printf("%-15s (%d, %d)", Token::Name(value), beg, end);
-    if (literal_length > 0) {
+    if (literal.get() != NULL) {
       // TODO(dcarney): need some sort of checksum.
       for (int i = 0; i < literal_length; i++) {
         printf(is_one_byte ? " %02x" : " %04x", literal[i]);
@@ -288,6 +271,16 @@
   }

  private:
+  Token::Value value;
+  int beg;
+  int end;
+  bool is_one_byte;
+  SmartArrayPointer<uint16_t> literal;
+  int literal_length;
+  // The location of the latest octal position when the token was seen.
+  int octal_beg;
+  int octal_end;
+
   DISALLOW_COPY_AND_ASSIGN(TokenWithLocation);
 };

@@ -307,7 +300,7 @@
     case UTF16: {
       CHECK_EQ(0, bytes % 2);
       Handle<String> result = isolate->factory()->NewStringFromTwoByte(
-          Vector<const uint16_t>(source, bytes / 2));
+          Vector<const uint16_t>(source, bytes / 2), false);
       stream.Reset(
new GenericStringUtf16CharacterStream(result, 0, result->length()));
       break;
=======================================
--- /branches/experimental/parser/src/lexer/lexer.cc Mon Mar 17 13:02:24 2014 UTC +++ /branches/experimental/parser/src/lexer/lexer.cc Mon Mar 17 15:57:19 2014 UTC
@@ -737,7 +737,8 @@
     EnsureLiteralIsValid(token, literal);
     return literal->is_one_byte() ?
factory->NewStringFromOneByte(literal->one_byte_string(), tenured) :
-        factory->NewStringFromTwoByte(literal->two_byte_string(), tenured);
+        factory->NewStringFromTwoByte(
+            literal->two_byte_string(), false, tenured);
   }
   int offset = 0, length = 0;
   LiteralOffsetAndLength<Char>(buffer_, token, &offset, &length);

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to