Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: src/json-parser.h

Issue 12440061: Improve SeqString::Truncate for latest allocated strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: renamed according to suggestion Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/json-stringifier.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-parser.h
diff --git a/src/json-parser.h b/src/json-parser.h
index 28ef8b33c8be019fb465830650d48bf41c40b23b..8561b0414de37b31488ed64c45992b377a0cbeb7 100644
--- a/src/json-parser.h
+++ b/src/json-parser.h
@@ -501,10 +501,10 @@ Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
int count = end - start;
int max_length = count + source_length_ - position_;
int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count));
- Handle<StringType> seq_str =
+ Handle<StringType> seq_string =
NewRawString<StringType>(factory(), length, pretenure_);
// Copy prefix into seq_str.
- SinkChar* dest = seq_str->GetChars();
+ SinkChar* dest = seq_string->GetChars();
String::WriteToFlat(*prefix, dest, start, end);
while (c0_ != '"') {
@@ -512,7 +512,7 @@ Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
if (c0_ < 0x20) return Handle<String>::null();
if (count >= length) {
// We need to create a longer sequential string for the result.
- return SlowScanJsonString<StringType, SinkChar>(seq_str, 0, count);
+ return SlowScanJsonString<StringType, SinkChar>(seq_string, 0, count);
}
if (c0_ != '\\') {
// If the sink can contain UC16 characters, or source_ contains only
@@ -522,11 +522,11 @@ Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
if (sizeof(SinkChar) == kUC16Size ||
seq_ascii ||
c0_ <= String::kMaxOneByteCharCode) {
- SeqStringSet(seq_str, count++, c0_);
+ SeqStringSet(seq_string, count++, c0_);
Advance();
} else {
// StringType is SeqOneByteString and we just read a non-ASCII char.
- return SlowScanJsonString<SeqTwoByteString, uc16>(seq_str, 0, count);
+ return SlowScanJsonString<SeqTwoByteString, uc16>(seq_string, 0, count);
}
} else {
Advance(); // Advance past the \.
@@ -534,22 +534,22 @@ Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
case '"':
case '\\':
case '/':
- SeqStringSet(seq_str, count++, c0_);
+ SeqStringSet(seq_string, count++, c0_);
break;
case 'b':
- SeqStringSet(seq_str, count++, '\x08');
+ SeqStringSet(seq_string, count++, '\x08');
break;
case 'f':
- SeqStringSet(seq_str, count++, '\x0c');
+ SeqStringSet(seq_string, count++, '\x0c');
break;
case 'n':
- SeqStringSet(seq_str, count++, '\x0a');
+ SeqStringSet(seq_string, count++, '\x0a');
break;
case 'r':
- SeqStringSet(seq_str, count++, '\x0d');
+ SeqStringSet(seq_string, count++, '\x0d');
break;
case 't':
- SeqStringSet(seq_str, count++, '\x09');
+ SeqStringSet(seq_string, count++, '\x09');
break;
case 'u': {
uc32 value = 0;
@@ -563,13 +563,13 @@ Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
}
if (sizeof(SinkChar) == kUC16Size ||
value <= String::kMaxOneByteCharCode) {
- SeqStringSet(seq_str, count++, value);
+ SeqStringSet(seq_string, count++, value);
break;
} else {
// StringType is SeqOneByteString and we just read a non-ASCII char.
position_ -= 6; // Rewind position_ to \ in \uxxxx.
Advance();
- return SlowScanJsonString<SeqTwoByteString, uc16>(seq_str,
+ return SlowScanJsonString<SeqTwoByteString, uc16>(seq_string,
0,
count);
}
@@ -580,23 +580,13 @@ Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
Advance();
}
}
- // Shrink seq_string length to count.
- if (isolate()->heap()->InNewSpace(*seq_str)) {
- isolate()->heap()->new_space()->
- template ShrinkStringAtAllocationBoundary<StringType>(
- *seq_str, count);
- } else {
- int string_size = StringType::SizeFor(count);
- int allocated_string_size = StringType::SizeFor(length);
- int delta = allocated_string_size - string_size;
- Address start_filler_object = seq_str->address() + string_size;
- seq_str->set_length(count);
- isolate()->heap()->CreateFillerObjectAt(start_filler_object, delta);
- }
+
ASSERT_EQ('"', c0_);
// Advance past the last '"'.
AdvanceSkipWhitespace();
- return seq_str;
+
+ // Shrink seq_string length to count and return.
+ return SeqString::Truncate(seq_string, count);
}
@@ -623,8 +613,8 @@ Handle<String> JsonParser<seq_ascii>::ScanJsonString() {
int beg_pos = position_;
position_ = position;
return SlowScanJsonString<SeqOneByteString, uint8_t>(source_,
- beg_pos,
- position_);
+ beg_pos,
+ position_);
}
if (c0 < 0x20) return Handle<String>::null();
if (static_cast<uint32_t>(c0) >
« no previous file with comments | « no previous file | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698