Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 0, | 573 0, |
| 574 count); | 574 count); |
| 575 } | 575 } |
| 576 } | 576 } |
| 577 default: | 577 default: |
| 578 return Handle<String>::null(); | 578 return Handle<String>::null(); |
| 579 } | 579 } |
| 580 Advance(); | 580 Advance(); |
| 581 } | 581 } |
| 582 } | 582 } |
| 583 // Shrink seq_string length to count. | 583 |
| 584 if (isolate()->heap()->InNewSpace(*seq_str)) { | |
| 585 isolate()->heap()->new_space()-> | |
| 586 template ShrinkStringAtAllocationBoundary<StringType>( | |
| 587 *seq_str, count); | |
| 588 } else { | |
| 589 int string_size = StringType::SizeFor(count); | |
| 590 int allocated_string_size = StringType::SizeFor(length); | |
| 591 int delta = allocated_string_size - string_size; | |
| 592 Address start_filler_object = seq_str->address() + string_size; | |
| 593 seq_str->set_length(count); | |
| 594 isolate()->heap()->CreateFillerObjectAt(start_filler_object, delta); | |
| 595 } | |
| 596 ASSERT_EQ('"', c0_); | 584 ASSERT_EQ('"', c0_); |
| 597 // Advance past the last '"'. | 585 // Advance past the last '"'. |
| 598 AdvanceSkipWhitespace(); | 586 AdvanceSkipWhitespace(); |
| 587 | |
| 588 // Shrink seq_string length to count and return. | |
|
Hannes Payer (out of office)
2013/03/21 12:48:30
See comment in src/objects.h. I would let Truncate
| |
| 589 if (count == 0) { | |
| 590 return isolate_->factory()->empty_string(); | |
| 591 } | |
| 592 SeqString::cast(*seq_str)->Truncate(count); | |
| 599 return seq_str; | 593 return seq_str; |
| 600 } | 594 } |
| 601 | 595 |
| 602 | 596 |
| 603 template <bool seq_ascii> | 597 template <bool seq_ascii> |
| 604 template <bool is_internalized> | 598 template <bool is_internalized> |
| 605 Handle<String> JsonParser<seq_ascii>::ScanJsonString() { | 599 Handle<String> JsonParser<seq_ascii>::ScanJsonString() { |
| 606 ASSERT_EQ('"', c0_); | 600 ASSERT_EQ('"', c0_); |
| 607 Advance(); | 601 Advance(); |
| 608 if (c0_ == '"') { | 602 if (c0_ == '"') { |
| 609 AdvanceSkipWhitespace(); | 603 AdvanceSkipWhitespace(); |
| 610 return factory()->empty_string(); | 604 return factory()->empty_string(); |
| 611 } | 605 } |
| 612 | 606 |
| 613 if (seq_ascii && is_internalized) { | 607 if (seq_ascii && is_internalized) { |
| 614 // Fast path for existing internalized strings. If the the string being | 608 // Fast path for existing internalized strings. If the the string being |
| 615 // parsed is not a known internalized string, contains backslashes or | 609 // parsed is not a known internalized string, contains backslashes or |
| 616 // unexpectedly reaches the end of string, return with an empty handle. | 610 // unexpectedly reaches the end of string, return with an empty handle. |
| 617 uint32_t running_hash = isolate()->heap()->HashSeed(); | 611 uint32_t running_hash = isolate()->heap()->HashSeed(); |
| 618 int position = position_; | 612 int position = position_; |
| 619 uc32 c0 = c0_; | 613 uc32 c0 = c0_; |
| 620 do { | 614 do { |
| 621 if (c0 == '\\') { | 615 if (c0 == '\\') { |
| 622 c0_ = c0; | 616 c0_ = c0; |
| 623 int beg_pos = position_; | 617 int beg_pos = position_; |
| 624 position_ = position; | 618 position_ = position; |
| 625 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, | 619 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, |
| 626 beg_pos, | 620 beg_pos, |
| 627 position_); | 621 position_); |
| 628 } | 622 } |
| 629 if (c0 < 0x20) return Handle<String>::null(); | 623 if (c0 < 0x20) return Handle<String>::null(); |
| 630 if (static_cast<uint32_t>(c0) > | 624 if (static_cast<uint32_t>(c0) > |
| 631 unibrow::Utf16::kMaxNonSurrogateCharCode) { | 625 unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 632 running_hash = | 626 running_hash = |
| 633 StringHasher::AddCharacterCore(running_hash, | 627 StringHasher::AddCharacterCore(running_hash, |
| 634 unibrow::Utf16::LeadSurrogate(c0)); | 628 unibrow::Utf16::LeadSurrogate(c0)); |
| 635 running_hash = | 629 running_hash = |
| 636 StringHasher::AddCharacterCore(running_hash, | 630 StringHasher::AddCharacterCore(running_hash, |
| 637 unibrow::Utf16::TrailSurrogate(c0)); | 631 unibrow::Utf16::TrailSurrogate(c0)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 } | 693 } |
| 700 ASSERT_EQ('"', c0_); | 694 ASSERT_EQ('"', c0_); |
| 701 // Advance past the last '"'. | 695 // Advance past the last '"'. |
| 702 AdvanceSkipWhitespace(); | 696 AdvanceSkipWhitespace(); |
| 703 return result; | 697 return result; |
| 704 } | 698 } |
| 705 | 699 |
| 706 } } // namespace v8::internal | 700 } } // namespace v8::internal |
| 707 | 701 |
| 708 #endif // V8_JSON_PARSER_H_ | 702 #endif // V8_JSON_PARSER_H_ |
| OLD | NEW |