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

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

Issue 11358065: Improve handle allocation in JSON.parse. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 8 years, 1 month 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 | « no previous file | no next file » | 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 uc32 c0_; 169 uc32 c0_;
170 int position_; 170 int position_;
171 Zone* zone_; 171 Zone* zone_;
172 }; 172 };
173 173
174 template <bool seq_ascii> 174 template <bool seq_ascii>
175 Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source, 175 Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source,
176 Zone* zone) { 176 Zone* zone) {
177 isolate_ = source->map()->GetHeap()->isolate(); 177 isolate_ = source->map()->GetHeap()->isolate();
178 factory_ = isolate_->factory(); 178 factory_ = isolate_->factory();
179 object_constructor_ = 179 object_constructor_ = Handle<JSFunction>(
180 Handle<JSFunction>(isolate()->native_context()->object_function()); 180 isolate()->native_context()->object_function(), isolate());
181 zone_ = zone; 181 zone_ = zone;
182 FlattenString(source); 182 FlattenString(source);
183 source_ = source; 183 source_ = source;
184 source_length_ = source_->length(); 184 source_length_ = source_->length();
185 pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED; 185 pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED;
186 186
187 // Optimized fast case where we only have ASCII characters. 187 // Optimized fast case where we only have ASCII characters.
188 if (seq_ascii) { 188 if (seq_ascii) {
189 seq_source_ = Handle<SeqAsciiString>::cast(source_); 189 seq_source_ = Handle<SeqAsciiString>::cast(source_);
190 } 190 }
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 604 }
605 605
606 606
607 template <bool seq_ascii> 607 template <bool seq_ascii>
608 template <bool is_symbol> 608 template <bool is_symbol>
609 Handle<String> JsonParser<seq_ascii>::ScanJsonString() { 609 Handle<String> JsonParser<seq_ascii>::ScanJsonString() {
610 ASSERT_EQ('"', c0_); 610 ASSERT_EQ('"', c0_);
611 Advance(); 611 Advance();
612 if (c0_ == '"') { 612 if (c0_ == '"') {
613 AdvanceSkipWhitespace(); 613 AdvanceSkipWhitespace();
614 return Handle<String>(isolate()->heap()->empty_string()); 614 return factory()->empty_string();
615 } 615 }
616 616
617 if (seq_ascii && is_symbol) { 617 if (seq_ascii && is_symbol) {
618 // Fast path for existing symbols. If the the string being parsed is not 618 // Fast path for existing symbols. If the the string being parsed is not
619 // a known symbol, contains backslashes or unexpectedly reaches the end of 619 // a known symbol, contains backslashes or unexpectedly reaches the end of
620 // string, return with an empty handle. 620 // string, return with an empty handle.
621 uint32_t running_hash = isolate()->heap()->HashSeed(); 621 uint32_t running_hash = isolate()->heap()->HashSeed();
622 int position = position_; 622 int position = position_;
623 uc32 c0 = c0_; 623 uc32 c0 = c0_;
624 do { 624 do {
(...skipping 25 matching lines...) Expand all
650 if (element == isolate()->heap()->undefined_value()) { 650 if (element == isolate()->heap()->undefined_value()) {
651 // Lookup failure. 651 // Lookup failure.
652 break; 652 break;
653 } 653 }
654 if (element != isolate()->heap()->the_hole_value() && 654 if (element != isolate()->heap()->the_hole_value() &&
655 String::cast(element)->IsAsciiEqualTo(string_vector)) { 655 String::cast(element)->IsAsciiEqualTo(string_vector)) {
656 // Lookup success, update the current position. 656 // Lookup success, update the current position.
657 position_ = position; 657 position_ = position;
658 // Advance past the last '"'. 658 // Advance past the last '"'.
659 AdvanceSkipWhitespace(); 659 AdvanceSkipWhitespace();
660 return Handle<String>(String::cast(element)); 660 return Handle<String>(String::cast(element), isolate());
661 } 661 }
662 entry = SymbolTable::NextProbe(entry, count++, capacity); 662 entry = SymbolTable::NextProbe(entry, count++, capacity);
663 } 663 }
664 } 664 }
665 665
666 int beg_pos = position_; 666 int beg_pos = position_;
667 // Fast case for ASCII only without escape characters. 667 // Fast case for ASCII only without escape characters.
668 do { 668 do {
669 // Check for control character (0x00-0x1f) or unterminated string (<0). 669 // Check for control character (0x00-0x1f) or unterminated string (<0).
670 if (c0_ < 0x20) return Handle<String>::null(); 670 if (c0_ < 0x20) return Handle<String>::null();
(...skipping 24 matching lines...) Expand all
695 } 695 }
696 ASSERT_EQ('"', c0_); 696 ASSERT_EQ('"', c0_);
697 // Advance past the last '"'. 697 // Advance past the last '"'.
698 AdvanceSkipWhitespace(); 698 AdvanceSkipWhitespace();
699 return result; 699 return result;
700 } 700 }
701 701
702 } } // namespace v8::internal 702 } } // namespace v8::internal
703 703
704 #endif // V8_JSON_PARSER_H_ 704 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698