Reviewers: Igor Sheludko,

Description:
Do fewer encoding checks in FlatStringReader used in the JSON stringifier.

[email protected]

Please review this at https://codereview.chromium.org/740673002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+17, -3 lines):
  M src/json-stringifier.h
  M src/objects.h
  M src/objects-inl.h


Index: src/json-stringifier.h
diff --git a/src/json-stringifier.h b/src/json-stringifier.h
index 4cdf31e45696f08f0a90c4fc31cc26948c09ff72..cbceaaead79c9c1a2f4efdc80fecae95a729089b 100644
--- a/src/json-stringifier.h
+++ b/src/json-stringifier.h
@@ -641,7 +641,7 @@ void BasicJsonStringifier::SerializeString_(Handle<String> string) {
   } else {
     FlatStringReader reader(isolate_, string);
     for (int i = 0; i < reader.length(); i++) {
-      SrcChar c = static_cast<SrcChar>(reader.Get(i));
+      SrcChar c = reader.Get<SrcChar>(i);
       if (DoNotEscape(c)) {
         builder_.Append<SrcChar, DestChar>(c);
       } else {
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 62f04b831aeb91b86630e487cdaa4ae64d25b621..ede427bf07666b38d4eadcbabbbcc80822fd8942 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -473,10 +473,22 @@ STATIC_ASSERT((kExternalStringTag | kTwoByteStringTag) ==

 STATIC_ASSERT(v8::String::TWO_BYTE_ENCODING == kTwoByteStringTag);

+
 uc32 FlatStringReader::Get(int index) {
-  DCHECK(0 <= index && index <= length_);
   if (is_one_byte_) {
-    return static_cast<const byte*>(start_)[index];
+    return Get<uint8_t>(index);
+  } else {
+    return Get<uc16>(index);
+  }
+}
+
+
+template <typename Char>
+Char FlatStringReader::Get(int index) {
+  DCHECK_EQ(is_one_byte_, sizeof(Char) == 1);
+  DCHECK(0 <= index && index <= length_);
+  if (sizeof(Char) == 1) {
+    return static_cast<const uint8_t*>(start_)[index];
   } else {
     return static_cast<const uc16*>(start_)[index];
   }
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index b63b1c3b45f741293b292dae432464bda8454d78..a86253d5a5b62c82244007dc44426faf28e7bb6b 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -9401,6 +9401,8 @@ class FlatStringReader : public Relocatable {
   FlatStringReader(Isolate* isolate, Vector<const char> input);
   void PostGarbageCollection();
   inline uc32 Get(int index);
+  template <typename Char>
+  inline Char Get(int index);
   int length() { return length_; }
  private:
   String** str_;


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