| OLD | NEW |
| 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 Loading... |
| 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 object = FlattenGetString(object); | 298 FlattenString(object); |
| 299 ASSERT(object->IsFlat()); | 299 ASSERT(object->IsFlat()); |
| 300 if (object->IsOneByteRepresentation()) { | 300 if (object->IsOneByteRepresentationUnderneath()) { |
| 301 Handle<String> result = | 301 Handle<String> result = |
| 302 isolate->factory()->NewRawOneByteString(worst_case_length); | 302 isolate->factory()->NewRawOneByteString(worst_case_length); |
| 303 AssertNoAllocation no_alloc; | 303 AssertNoAllocation no_alloc; |
| 304 const uint8_t* start = object->IsSeqOneByteString() | |
| 305 ? SeqOneByteString::cast(*object)->GetChars() | |
| 306 : ExternalAsciiString::cast(*object)->GetChars(); | |
| 307 return StringifyString_<SeqOneByteString>( | 304 return StringifyString_<SeqOneByteString>( |
| 308 isolate, | 305 isolate, |
| 309 Vector<const uint8_t>(start, object->length()), | 306 object->GetFlatContent().ToOneByteVector(), |
| 310 result); | 307 result); |
| 311 } else { | 308 } else { |
| 312 Handle<String> result = | 309 Handle<String> result = |
| 313 isolate->factory()->NewRawTwoByteString(worst_case_length); | 310 isolate->factory()->NewRawTwoByteString(worst_case_length); |
| 314 AssertNoAllocation no_alloc; | 311 AssertNoAllocation no_alloc; |
| 315 const uc16* start = object->IsSeqTwoByteString() | |
| 316 ? SeqTwoByteString::cast(*object)->GetChars() | |
| 317 : ExternalTwoByteString::cast(*object)->GetChars(); | |
| 318 return StringifyString_<SeqTwoByteString>( | 312 return StringifyString_<SeqTwoByteString>( |
| 319 isolate, | 313 isolate, |
| 320 Vector<const uc16>(start, object->length()), | 314 object->GetFlatContent().ToUC16Vector(), |
| 321 result); | 315 result); |
| 322 } | 316 } |
| 323 } | 317 } |
| 324 | 318 |
| 325 | 319 |
| 326 template <typename ResultType, typename Char> | 320 template <typename ResultType, typename Char> |
| 327 MaybeObject* BasicJsonStringifier::StringifyString_(Isolate* isolate, | 321 MaybeObject* BasicJsonStringifier::StringifyString_(Isolate* isolate, |
| 328 Vector<Char> vector, | 322 Vector<Char> vector, |
| 329 Handle<String> result) { | 323 Handle<String> result) { |
| 330 AssertNoAllocation no_allocation; | 324 AssertNoAllocation no_allocation; |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 SerializeString_<false, uint8_t>(object); | 839 SerializeString_<false, uint8_t>(object); |
| 846 } else { | 840 } else { |
| 847 SerializeString_<false, uc16>(object); | 841 SerializeString_<false, uc16>(object); |
| 848 } | 842 } |
| 849 } | 843 } |
| 850 } | 844 } |
| 851 | 845 |
| 852 } } // namespace v8::internal | 846 } } // namespace v8::internal |
| 853 | 847 |
| 854 #endif // V8_JSON_STRINGIFIER_H_ | 848 #endif // V8_JSON_STRINGIFIER_H_ |
| OLD | NEW |