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

Unified Diff: src/json-stringifier.h

Issue 12825016: Fix JSON.stringifier's slow path wrt external strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 | test/mjsunit/json2.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-stringifier.h
diff --git a/src/json-stringifier.h b/src/json-stringifier.h
index 418d4794595367f088e09cbb519d65209ff7bd96..f78493d7dfc8edba54d4f125146eee26377f6355 100644
--- a/src/json-stringifier.h
+++ b/src/json-stringifier.h
@@ -87,9 +87,9 @@ class BasicJsonStringifier BASE_EMBEDDED {
bool deferred_comma,
bool deferred_key);
- template <typename StringType>
+ template <typename ResultType, typename Char>
INLINE(static MaybeObject* StringifyString_(Isolate* isolate,
- Handle<String> string,
+ Vector<Char> vector,
Handle<String> result));
// Entry point to serialize the object.
@@ -295,36 +295,37 @@ MaybeObject* BasicJsonStringifier::StringifyString(Isolate* isolate,
return stringifier.Stringify(object);
}
- object = FlattenGetString(object);
- if (object->IsSeqOneByteString()) {
+ FlattenString(object);
+ String::FlatContent flat = object->GetFlatContent();
+ if (flat.IsAscii()) {
return StringifyString_<SeqOneByteString>(
isolate,
- object,
+ flat.ToOneByteVector(),
isolate->factory()->NewRawOneByteString(worst_case_length));
} else {
return StringifyString_<SeqTwoByteString>(
isolate,
- object,
+ flat.ToUC16Vector(),
isolate->factory()->NewRawTwoByteString(worst_case_length));
}
}
-template <typename StringType>
+template <typename ResultType, typename Char>
MaybeObject* BasicJsonStringifier::StringifyString_(Isolate* isolate,
- Handle<String> string,
+ Vector<Char> vector,
Handle<String> result) {
AssertNoAllocation no_allocation;
int final_size = 0;
- StringType* dest = StringType::cast(*result);
+ ResultType* dest = ResultType::cast(*result);
dest->Set(final_size++, '\"');
- final_size += SerializeStringUnchecked_(StringType::cast(*string)->GetChars(),
+ final_size += SerializeStringUnchecked_(vector.start(),
dest->GetChars() + 1,
- string->length());
+ vector.length());
dest->Set(final_size++, '\"');
if (isolate->heap()->InNewSpace(*result)) {
// In new space, simply lower the allocation top to fit the actual size.
- isolate->heap()->new_space()->ShrinkStringAtAllocationBoundary<StringType>(
+ isolate->heap()->new_space()->ShrinkStringAtAllocationBoundary<ResultType>(
*result, final_size);
return *result;
} else {
« no previous file with comments | « no previous file | test/mjsunit/json2.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698