Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: src/json-parser.h

Issue 11028027: Revert trunk to bleeding_edge at r12484 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.h ('k') | src/jsregexp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 } 65 }
66 66
67 // The JSON lexical grammar is specified in the ECMAScript 5 standard, 67 // The JSON lexical grammar is specified in the ECMAScript 5 standard,
68 // section 15.12.1.1. The only allowed whitespace characters between tokens 68 // section 15.12.1.1. The only allowed whitespace characters between tokens
69 // are tab, carriage-return, newline and space. 69 // are tab, carriage-return, newline and space.
70 70
71 inline void AdvanceSkipWhitespace() { 71 inline void AdvanceSkipWhitespace() {
72 do { 72 do {
73 Advance(); 73 Advance();
74 } while (c0_ == ' ' || c0_ == '\t' || c0_ == '\n' || c0_ == '\r'); 74 } while (c0_ == '\t' || c0_ == '\r' || c0_ == '\n' || c0_ == ' ');
75 } 75 }
76 76
77 inline void SkipWhitespace() { 77 inline void SkipWhitespace() {
78 while (c0_ == ' ' || c0_ == '\t' || c0_ == '\n' || c0_ == '\r') { 78 while (c0_ == '\t' || c0_ == '\r' || c0_ == '\n' || c0_ == ' ') {
79 Advance(); 79 Advance();
80 } 80 }
81 } 81 }
82 82
83 inline uc32 AdvanceGetChar() { 83 inline uc32 AdvanceGetChar() {
84 Advance(); 84 Advance();
85 return c0_; 85 return c0_;
86 } 86 }
87 87
88 // Checks that current charater is c. 88 // Checks that current charater is c.
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 556
557 template <bool seq_ascii> 557 template <bool seq_ascii>
558 template <bool is_symbol> 558 template <bool is_symbol>
559 Handle<String> JsonParser<seq_ascii>::ScanJsonString() { 559 Handle<String> JsonParser<seq_ascii>::ScanJsonString() {
560 ASSERT_EQ('"', c0_); 560 ASSERT_EQ('"', c0_);
561 Advance(); 561 Advance();
562 if (c0_ == '"') { 562 if (c0_ == '"') {
563 AdvanceSkipWhitespace(); 563 AdvanceSkipWhitespace();
564 return Handle<String>(isolate()->heap()->empty_string()); 564 return Handle<String>(isolate()->heap()->empty_string());
565 } 565 }
566
567 if (seq_ascii && is_symbol) {
568 // Fast path for existing symbols. If the the string being parsed is not
569 // a known symbol, contains backslashes or unexpectedly reaches the end of
570 // string, return with an empty handle.
571 uint32_t running_hash = isolate()->heap()->HashSeed();
572 int position = position_;
573 uc32 c0 = c0_;
574 do {
575 if (c0 == '\\') {
576 return SlowScanJsonString<SeqAsciiString, char>(source_,
577 position_,
578 position);
579 }
580 if (c0_ < 0x20) return Handle<String>::null();
581 running_hash = StringHasher::AddCharacterCore(running_hash, c0);
582 position++;
583 if (position >= source_length_) return Handle<String>::null();
584 c0 = seq_source_->SeqAsciiStringGet(position);
585 } while (c0 != '"');
586 int length = position - position_;
587 uint32_t hash = (length <= String::kMaxHashCalcLength)
588 ? StringHasher::GetHashCore(running_hash) : length;
589 Vector<const char> string_vector(
590 seq_source_->GetChars() + position_, length);
591 SymbolTable* symbol_table = isolate()->heap()->symbol_table();
592 uint32_t capacity = symbol_table->Capacity();
593 uint32_t entry = SymbolTable::FirstProbe(hash, capacity);
594 uint32_t count = 1;
595 while (true) {
596 Object* element = symbol_table->KeyAt(entry);
597 if (element == isolate()->heap()->raw_unchecked_undefined_value()) {
598 // Lookup failure.
599 break;
600 }
601 if (element != isolate()->heap()->raw_unchecked_the_hole_value() &&
602 String::cast(element)->IsAsciiEqualTo(string_vector)) {
603 // Lookup success, update the current position.
604 position_ = position;
605 // Advance past the last '"'.
606 AdvanceSkipWhitespace();
607 return Handle<String>(String::cast(element));
608 }
609 entry = SymbolTable::NextProbe(entry, count++, capacity);
610 }
611 }
612
613 int beg_pos = position_; 566 int beg_pos = position_;
614 // Fast case for ASCII only without escape characters. 567 // Fast case for ASCII only without escape characters.
615 do { 568 do {
616 // Check for control character (0x00-0x1f) or unterminated string (<0). 569 // Check for control character (0x00-0x1f) or unterminated string (<0).
617 if (c0_ < 0x20) return Handle<String>::null(); 570 if (c0_ < 0x20) return Handle<String>::null();
618 if (c0_ != '\\') { 571 if (c0_ != '\\') {
619 if (seq_ascii || c0_ <= kMaxAsciiCharCode) { 572 if (seq_ascii || c0_ <= kMaxAsciiCharCode) {
620 Advance(); 573 Advance();
621 } else { 574 } else {
622 return SlowScanJsonString<SeqTwoByteString, uc16>(source_, 575 return SlowScanJsonString<SeqTwoByteString, uc16>(source_,
(...skipping 19 matching lines...) Expand all
642 } 595 }
643 ASSERT_EQ('"', c0_); 596 ASSERT_EQ('"', c0_);
644 // Advance past the last '"'. 597 // Advance past the last '"'.
645 AdvanceSkipWhitespace(); 598 AdvanceSkipWhitespace();
646 return result; 599 return result;
647 } 600 }
648 601
649 } } // namespace v8::internal 602 } } // namespace v8::internal
650 603
651 #endif // V8_JSON_PARSER_H_ 604 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/jsregexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698