| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_JSON_STRINGIFIER_H_ | 5 #ifndef V8_JSON_STRINGIFIER_H_ |
| 6 #define V8_JSON_STRINGIFIER_H_ | 6 #define V8_JSON_STRINGIFIER_H_ |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 // an escaped character is 6. Shifting the remainin string length right by 3 | 632 // an escaped character is 6. Shifting the remainin string length right by 3 |
| 633 // is a more pessimistic estimate, but faster to calculate. | 633 // is a more pessimistic estimate, but faster to calculate. |
| 634 int worst_case_length = length << 3; | 634 int worst_case_length = length << 3; |
| 635 if (builder_.CurrentPartCanFit(worst_case_length)) { | 635 if (builder_.CurrentPartCanFit(worst_case_length)) { |
| 636 DisallowHeapAllocation no_gc; | 636 DisallowHeapAllocation no_gc; |
| 637 Vector<const SrcChar> vector = GetCharVector<SrcChar>(string); | 637 Vector<const SrcChar> vector = GetCharVector<SrcChar>(string); |
| 638 IncrementalStringBuilder::NoExtendBuilder<DestChar> no_extend( | 638 IncrementalStringBuilder::NoExtendBuilder<DestChar> no_extend( |
| 639 &builder_, worst_case_length); | 639 &builder_, worst_case_length); |
| 640 SerializeStringUnchecked_(vector, &no_extend); | 640 SerializeStringUnchecked_(vector, &no_extend); |
| 641 } else { | 641 } else { |
| 642 String* string_location = NULL; | 642 FlatStringReader reader(isolate_, string); |
| 643 Vector<const SrcChar> vector(NULL, 0); | 643 for (int i = 0; i < reader.length(); i++) { |
| 644 for (int i = 0; i < length; i++) { | 644 SrcChar c = static_cast<SrcChar>(reader.Get(i)); |
| 645 // If GC moved the string, we need to refresh the vector. | |
| 646 if (*string != string_location) { | |
| 647 DisallowHeapAllocation no_gc; | |
| 648 // This does not actually prevent the string from being relocated later. | |
| 649 vector = GetCharVector<SrcChar>(string); | |
| 650 string_location = *string; | |
| 651 } | |
| 652 SrcChar c = vector[i]; | |
| 653 if (DoNotEscape(c)) { | 645 if (DoNotEscape(c)) { |
| 654 builder_.Append<SrcChar, DestChar>(c); | 646 builder_.Append<SrcChar, DestChar>(c); |
| 655 } else { | 647 } else { |
| 656 builder_.AppendCString(&JsonEscapeTable[c * kJsonEscapeTableEntrySize]); | 648 builder_.AppendCString(&JsonEscapeTable[c * kJsonEscapeTableEntrySize]); |
| 657 } | 649 } |
| 658 } | 650 } |
| 659 } | 651 } |
| 660 | 652 |
| 661 builder_.Append<uint8_t, DestChar>('"'); | 653 builder_.Append<uint8_t, DestChar>('"'); |
| 662 } | 654 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 SerializeString_<uint8_t, uc16>(object); | 697 SerializeString_<uint8_t, uc16>(object); |
| 706 } else { | 698 } else { |
| 707 SerializeString_<uc16, uc16>(object); | 699 SerializeString_<uc16, uc16>(object); |
| 708 } | 700 } |
| 709 } | 701 } |
| 710 } | 702 } |
| 711 | 703 |
| 712 } } // namespace v8::internal | 704 } } // namespace v8::internal |
| 713 | 705 |
| 714 #endif // V8_JSON_STRINGIFIER_H_ | 706 #endif // V8_JSON_STRINGIFIER_H_ |
| OLD | NEW |