Commit 472f8823 authored by yangguo's avatar yangguo Committed by Commit bot

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

R=ishell@chromium.org

Review URL: https://codereview.chromium.org/740673002

Cr-Commit-Position: refs/heads/master@{#25416}
parent 2ad22375
......@@ -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 {
......
......@@ -473,12 +473,24 @@ 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<Char>(static_cast<const uint8_t*>(start_)[index]);
} else {
return static_cast<const uc16*>(start_)[index];
return static_cast<Char>(static_cast<const uc16*>(start_)[index]);
}
}
......
......@@ -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_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment