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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 static const int kJsonQuoteWorstCaseBlowup = 6; | 298 static const int kJsonQuoteWorstCaseBlowup = 6; |
299 static const int kSpaceForQuotes = 2; | 299 static const int kSpaceForQuotes = 2; |
300 int worst_case_length = | 300 int worst_case_length = |
301 object->length() * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; | 301 object->length() * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; |
302 | 302 |
303 if (worst_case_length > 32 * KB) { // Slow path if too large. | 303 if (worst_case_length > 32 * KB) { // Slow path if too large. |
304 BasicJsonStringifier stringifier(isolate); | 304 BasicJsonStringifier stringifier(isolate); |
305 return stringifier.Stringify(object); | 305 return stringifier.Stringify(object); |
306 } | 306 } |
307 | 307 |
308 FlattenString(object); | 308 object = String::Flatten(object); |
309 ASSERT(object->IsFlat()); | 309 ASSERT(object->IsFlat()); |
310 if (object->IsOneByteRepresentationUnderneath()) { | 310 if (object->IsOneByteRepresentationUnderneath()) { |
311 Handle<String> result = isolate->factory()->NewRawOneByteString( | 311 Handle<String> result = isolate->factory()->NewRawOneByteString( |
312 worst_case_length).ToHandleChecked(); | 312 worst_case_length).ToHandleChecked(); |
313 DisallowHeapAllocation no_gc; | 313 DisallowHeapAllocation no_gc; |
314 return StringifyString_<SeqOneByteString>( | 314 return StringifyString_<SeqOneByteString>( |
315 isolate, | 315 isolate, |
316 object->GetFlatContent().ToOneByteVector(), | 316 object->GetFlatContent().ToOneByteVector(), |
317 result); | 317 result); |
318 } else { | 318 } else { |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 | 866 |
867 template <> | 867 template <> |
868 Vector<const uc16> BasicJsonStringifier::GetCharVector(Handle<String> string) { | 868 Vector<const uc16> BasicJsonStringifier::GetCharVector(Handle<String> string) { |
869 String::FlatContent flat = string->GetFlatContent(); | 869 String::FlatContent flat = string->GetFlatContent(); |
870 ASSERT(flat.IsTwoByte()); | 870 ASSERT(flat.IsTwoByte()); |
871 return flat.ToUC16Vector(); | 871 return flat.ToUC16Vector(); |
872 } | 872 } |
873 | 873 |
874 | 874 |
875 void BasicJsonStringifier::SerializeString(Handle<String> object) { | 875 void BasicJsonStringifier::SerializeString(Handle<String> object) { |
876 object = FlattenGetString(object); | 876 object = String::Flatten(object); |
877 if (is_ascii_) { | 877 if (is_ascii_) { |
878 if (object->IsOneByteRepresentationUnderneath()) { | 878 if (object->IsOneByteRepresentationUnderneath()) { |
879 SerializeString_<true, uint8_t>(object); | 879 SerializeString_<true, uint8_t>(object); |
880 } else { | 880 } else { |
881 ChangeEncoding(); | 881 ChangeEncoding(); |
882 SerializeString(object); | 882 SerializeString(object); |
883 } | 883 } |
884 } else { | 884 } else { |
885 if (object->IsOneByteRepresentationUnderneath()) { | 885 if (object->IsOneByteRepresentationUnderneath()) { |
886 SerializeString_<false, uint8_t>(object); | 886 SerializeString_<false, uint8_t>(object); |
887 } else { | 887 } else { |
888 SerializeString_<false, uc16>(object); | 888 SerializeString_<false, uc16>(object); |
889 } | 889 } |
890 } | 890 } |
891 } | 891 } |
892 | 892 |
893 } } // namespace v8::internal | 893 } } // namespace v8::internal |
894 | 894 |
895 #endif // V8_JSON_STRINGIFIER_H_ | 895 #endif // V8_JSON_STRINGIFIER_H_ |
OLD | NEW |