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 5234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5245 template <typename Char, typename StringType, bool comma> | 5245 template <typename Char, typename StringType, bool comma> |
5246 static MaybeObject* SlowQuoteJsonString(Isolate* isolate, | 5246 static MaybeObject* SlowQuoteJsonString(Isolate* isolate, |
5247 Vector<const Char> characters) { | 5247 Vector<const Char> characters) { |
5248 int length = characters.length(); | 5248 int length = characters.length(); |
5249 const Char* read_cursor = characters.start(); | 5249 const Char* read_cursor = characters.start(); |
5250 const Char* end = read_cursor + length; | 5250 const Char* end = read_cursor + length; |
5251 const int kSpaceForQuotes = 2 + (comma ? 1 :0); | 5251 const int kSpaceForQuotes = 2 + (comma ? 1 :0); |
5252 int quoted_length = kSpaceForQuotes; | 5252 int quoted_length = kSpaceForQuotes; |
5253 while (read_cursor < end) { | 5253 while (read_cursor < end) { |
5254 Char c = *(read_cursor++); | 5254 Char c = *(read_cursor++); |
5255 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) { | 5255 if (static_cast<unsigned>(c) >= kQuoteTableLength) { |
5256 quoted_length++; | 5256 quoted_length++; |
5257 } else { | 5257 } else { |
5258 quoted_length += JsonQuoteLengths[static_cast<unsigned>(c)]; | 5258 quoted_length += JsonQuoteLengths[static_cast<unsigned>(c)]; |
5259 } | 5259 } |
5260 } | 5260 } |
5261 MaybeObject* new_alloc = AllocateRawString<StringType>(isolate, | 5261 MaybeObject* new_alloc = AllocateRawString<StringType>(isolate, |
5262 quoted_length); | 5262 quoted_length); |
5263 Object* new_object; | 5263 Object* new_object; |
5264 if (!new_alloc->ToObject(&new_object)) { | 5264 if (!new_alloc->ToObject(&new_object)) { |
5265 return new_alloc; | 5265 return new_alloc; |
5266 } | 5266 } |
5267 StringType* new_string = StringType::cast(new_object); | 5267 StringType* new_string = StringType::cast(new_object); |
5268 | 5268 |
5269 Char* write_cursor = reinterpret_cast<Char*>( | 5269 Char* write_cursor = reinterpret_cast<Char*>( |
5270 new_string->address() + SeqString::kHeaderSize); | 5270 new_string->address() + SeqString::kHeaderSize); |
5271 if (comma) *(write_cursor++) = ','; | 5271 if (comma) *(write_cursor++) = ','; |
5272 *(write_cursor++) = '"'; | 5272 *(write_cursor++) = '"'; |
5273 | 5273 |
5274 read_cursor = characters.start(); | 5274 read_cursor = characters.start(); |
5275 while (read_cursor < end) { | 5275 while (read_cursor < end) { |
5276 Char c = *(read_cursor++); | 5276 Char c = *(read_cursor++); |
5277 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) { | 5277 if (static_cast<unsigned>(c) >= kQuoteTableLength) { |
5278 *(write_cursor++) = c; | 5278 *(write_cursor++) = c; |
5279 } else { | 5279 } else { |
5280 int len = JsonQuoteLengths[static_cast<unsigned>(c)]; | 5280 int len = JsonQuoteLengths[static_cast<unsigned>(c)]; |
5281 const char* replacement = JsonQuotes + | 5281 const char* replacement = JsonQuotes + |
5282 static_cast<unsigned>(c) * kJsonQuotesCharactersPerEntry; | 5282 static_cast<unsigned>(c) * kJsonQuotesCharactersPerEntry; |
5283 for (int i = 0; i < len; i++) { | 5283 for (int i = 0; i < len; i++) { |
5284 *write_cursor++ = *replacement++; | 5284 *write_cursor++ = *replacement++; |
5285 } | 5285 } |
5286 } | 5286 } |
5287 } | 5287 } |
5288 *(write_cursor++) = '"'; | 5288 *(write_cursor++) = '"'; |
5289 return new_string; | 5289 return new_string; |
5290 } | 5290 } |
5291 | 5291 |
5292 | 5292 |
5293 template <typename SinkChar, typename SourceChar> | 5293 template <typename SinkChar, typename SourceChar> |
5294 static inline SinkChar* WriteQuoteJsonString( | 5294 static inline SinkChar* WriteQuoteJsonString( |
5295 Isolate* isolate, | 5295 Isolate* isolate, |
5296 SinkChar* write_cursor, | 5296 SinkChar* write_cursor, |
5297 Vector<const SourceChar> characters) { | 5297 Vector<const SourceChar> characters) { |
5298 // SinkChar is only char if SourceChar is guaranteed to be char. | 5298 // SinkChar is only char if SourceChar is guaranteed to be char. |
5299 ASSERT(sizeof(SinkChar) >= sizeof(SourceChar)); | 5299 ASSERT(sizeof(SinkChar) >= sizeof(SourceChar)); |
5300 const SourceChar* read_cursor = characters.start(); | 5300 const SourceChar* read_cursor = characters.start(); |
5301 const SourceChar* end = read_cursor + characters.length(); | 5301 const SourceChar* end = read_cursor + characters.length(); |
5302 *(write_cursor++) = '"'; | 5302 *(write_cursor++) = '"'; |
5303 while (read_cursor < end) { | 5303 while (read_cursor < end) { |
5304 SourceChar c = *(read_cursor++); | 5304 SourceChar c = *(read_cursor++); |
5305 if (sizeof(SourceChar) > 1u && | 5305 if (static_cast<unsigned>(c) >= kQuoteTableLength) { |
5306 static_cast<unsigned>(c) >= kQuoteTableLength) { | |
5307 *(write_cursor++) = static_cast<SinkChar>(c); | 5306 *(write_cursor++) = static_cast<SinkChar>(c); |
5308 } else { | 5307 } else { |
5309 int len = JsonQuoteLengths[static_cast<unsigned>(c)]; | 5308 int len = JsonQuoteLengths[static_cast<unsigned>(c)]; |
5310 const char* replacement = JsonQuotes + | 5309 const char* replacement = JsonQuotes + |
5311 static_cast<unsigned>(c) * kJsonQuotesCharactersPerEntry; | 5310 static_cast<unsigned>(c) * kJsonQuotesCharactersPerEntry; |
5312 write_cursor[0] = replacement[0]; | 5311 write_cursor[0] = replacement[0]; |
5313 if (len > 1) { | 5312 if (len > 1) { |
5314 write_cursor[1] = replacement[1]; | 5313 write_cursor[1] = replacement[1]; |
5315 if (len > 2) { | 5314 if (len > 2) { |
5316 ASSERT(len == 6); | 5315 ASSERT(len == 6); |
(...skipping 8051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13368 // Handle last resort GC and make sure to allow future allocations | 13367 // Handle last resort GC and make sure to allow future allocations |
13369 // to grow the heap without causing GCs (if possible). | 13368 // to grow the heap without causing GCs (if possible). |
13370 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13369 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13371 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13370 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13372 "Runtime::PerformGC"); | 13371 "Runtime::PerformGC"); |
13373 } | 13372 } |
13374 } | 13373 } |
13375 | 13374 |
13376 | 13375 |
13377 } } // namespace v8::internal | 13376 } } // namespace v8::internal |
OLD | NEW |