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

Side by Side Diff: src/json-stringifier.h

Issue 13782002: Fix slow path of JSON.stringifier when GC strikes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-json-stringify-gc.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 static const int kJsonQuoteWorstCaseBlowup = 6; 288 static const int kJsonQuoteWorstCaseBlowup = 6;
289 static const int kSpaceForQuotes = 2; 289 static const int kSpaceForQuotes = 2;
290 int worst_case_length = 290 int worst_case_length =
291 object->length() * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; 291 object->length() * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes;
292 292
293 if (worst_case_length > 32 * KB) { // Slow path if too large. 293 if (worst_case_length > 32 * KB) { // Slow path if too large.
294 BasicJsonStringifier stringifier(isolate); 294 BasicJsonStringifier stringifier(isolate);
295 return stringifier.Stringify(object); 295 return stringifier.Stringify(object);
296 } 296 }
297 297
298 FlattenString(object); 298 object = FlattenGetString(object);
299 String::FlatContent flat = object->GetFlatContent(); 299 ASSERT(object->IsFlat());
300 if (flat.IsAscii()) { 300 if (object->IsOneByteRepresentation()) {
301 Handle<String> result =
302 isolate->factory()->NewRawOneByteString(worst_case_length);
303 AssertNoAllocation no_alloc;
304 const uint8_t* start = object->IsSeqOneByteString()
305 ? SeqOneByteString::cast(*object)->GetChars()
306 : ExternalAsciiString::cast(*object)->GetChars();
301 return StringifyString_<SeqOneByteString>( 307 return StringifyString_<SeqOneByteString>(
302 isolate, 308 isolate,
303 flat.ToOneByteVector(), 309 Vector<const uint8_t>(start, object->length()),
304 isolate->factory()->NewRawOneByteString(worst_case_length)); 310 result);
305 } else { 311 } else {
306 ASSERT(flat.IsTwoByte()); 312 Handle<String> result =
313 isolate->factory()->NewRawTwoByteString(worst_case_length);
314 AssertNoAllocation no_alloc;
315 const uc16* start = object->IsSeqTwoByteString()
316 ? SeqTwoByteString::cast(*object)->GetChars()
317 : ExternalTwoByteString::cast(*object)->GetChars();
307 return StringifyString_<SeqTwoByteString>( 318 return StringifyString_<SeqTwoByteString>(
308 isolate, 319 isolate,
309 flat.ToUC16Vector(), 320 Vector<const uc16>(start, object->length()),
310 isolate->factory()->NewRawTwoByteString(worst_case_length)); 321 result);
311 } 322 }
312 } 323 }
313 324
314 325
315 template <typename ResultType, typename Char> 326 template <typename ResultType, typename Char>
316 MaybeObject* BasicJsonStringifier::StringifyString_(Isolate* isolate, 327 MaybeObject* BasicJsonStringifier::StringifyString_(Isolate* isolate,
317 Vector<Char> vector, 328 Vector<Char> vector,
318 Handle<String> result) { 329 Handle<String> result) {
319 AssertNoAllocation no_allocation; 330 AssertNoAllocation no_allocation;
320 int final_size = 0; 331 int final_size = 0;
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 SerializeString_<false, uint8_t>(object); 845 SerializeString_<false, uint8_t>(object);
835 } else { 846 } else {
836 SerializeString_<false, uc16>(object); 847 SerializeString_<false, uc16>(object);
837 } 848 }
838 } 849 }
839 } 850 }
840 851
841 } } // namespace v8::internal 852 } } // namespace v8::internal
842 853
843 #endif // V8_JSON_STRINGIFIER_H_ 854 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-json-stringify-gc.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698