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

Side by Side Diff: src/scanner-base.cc

Issue 5545006: Optimized scanner to avoid virtual calls for every character read. (Closed)
Patch Set: Addressed review comments. Created 10 years 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
« no previous file with comments | « src/scanner-base.h ('k') | test/cctest/test-parsing.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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 17 matching lines...) Expand all
28 // Features shared by parsing and pre-parsing scanners. 28 // Features shared by parsing and pre-parsing scanners.
29 29
30 #include "../include/v8stdint.h" 30 #include "../include/v8stdint.h"
31 #include "scanner-base.h" 31 #include "scanner-base.h"
32 #include "char-predicates-inl.h" 32 #include "char-predicates-inl.h"
33 33
34 namespace v8 { 34 namespace v8 {
35 namespace internal { 35 namespace internal {
36 36
37 // ---------------------------------------------------------------------------- 37 // ----------------------------------------------------------------------------
38 // UTF16Buffer
39
40 UTF16Buffer::UTF16Buffer()
41 : pos_(0), end_(kNoEndPosition) { }
42
43 // ----------------------------------------------------------------------------
44 // LiteralCollector 38 // LiteralCollector
45 39
46 LiteralCollector::LiteralCollector() 40 LiteralCollector::LiteralCollector()
47 : buffer_(kInitialCapacity), recording_(false) { } 41 : buffer_(kInitialCapacity), recording_(false) { }
48 42
49 43
50 LiteralCollector::~LiteralCollector() {} 44 LiteralCollector::~LiteralCollector() {}
51 45
52 46
53 void LiteralCollector::AddCharSlow(uc32 c) { 47 void LiteralCollector::AddCharSlow(uc32 c) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 if (!kIsIdentifierPart.get(buffer->GetNext())) { 79 if (!kIsIdentifierPart.get(buffer->GetNext())) {
86 return false; 80 return false;
87 } 81 }
88 } 82 }
89 return true; 83 return true;
90 } 84 }
91 85
92 // ---------------------------------------------------------------------------- 86 // ----------------------------------------------------------------------------
93 // Scanner 87 // Scanner
94 88
95 Scanner::Scanner() : source_(NULL) {} 89 Scanner::Scanner() { }
96 90
97 91
98 uc32 Scanner::ScanHexEscape(uc32 c, int length) { 92 uc32 Scanner::ScanHexEscape(uc32 c, int length) {
99 ASSERT(length <= 4); // prevent overflow 93 ASSERT(length <= 4); // prevent overflow
100 94
101 uc32 digits[4]; 95 uc32 digits[4];
102 uc32 x = 0; 96 uc32 x = 0;
103 for (int i = 0; i < length; i++) { 97 for (int i = 0; i < length; i++) {
104 digits[i] = c0_; 98 digits[i] = c0_;
105 int d = HexValue(c0_); 99 int d = HexValue(c0_);
(...skipping 29 matching lines...) Expand all
135 x = nx; 129 x = nx;
136 Advance(); 130 Advance();
137 } 131 }
138 return x; 132 return x;
139 } 133 }
140 134
141 135
142 // ---------------------------------------------------------------------------- 136 // ----------------------------------------------------------------------------
143 // JavaScriptScanner 137 // JavaScriptScanner
144 138
145 JavaScriptScanner::JavaScriptScanner() 139 JavaScriptScanner::JavaScriptScanner() : Scanner() {}
146 : has_line_terminator_before_next_(false) {}
147 140
148 141
149 Token::Value JavaScriptScanner::Next() { 142 Token::Value JavaScriptScanner::Next() {
150 current_ = next_; 143 current_ = next_;
151 has_line_terminator_before_next_ = false; 144 has_line_terminator_before_next_ = false;
152 Scan(); 145 Scan();
153 return current_.token; 146 return current_.token;
154 } 147 }
155 148
156 149
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 // Continue scanning for tokens as long as we're just skipping 489 // Continue scanning for tokens as long as we're just skipping
497 // whitespace. 490 // whitespace.
498 } while (token == Token::WHITESPACE); 491 } while (token == Token::WHITESPACE);
499 492
500 next_.location.end_pos = source_pos(); 493 next_.location.end_pos = source_pos();
501 next_.token = token; 494 next_.token = token;
502 } 495 }
503 496
504 497
505 void JavaScriptScanner::SeekForward(int pos) { 498 void JavaScriptScanner::SeekForward(int pos) {
506 source_->SeekForward(pos - 1); 499 // After this call, we will have the token at the given position as
507 Advance(); 500 // the "next" token. The "current" token will be invalid.
508 // This function is only called to seek to the location 501 if (pos == next_.location.beg_pos) return;
509 // of the end of a function (at the "}" token). It doesn't matter 502 int current_pos = source_pos();
510 // whether there was a line terminator in the part we skip. 503 ASSERT_EQ(next_.location.end_pos, current_pos);
511 has_line_terminator_before_next_ = false; 504 // Positions inside the lookahead token aren't supported.
505 ASSERT(pos >= current_pos);
506 if (pos != current_pos) {
507 source_->SeekForward(pos - source_->pos());
508 Advance();
509 // This function is only called to seek to the location
510 // of the end of a function (at the "}" token). It doesn't matter
511 // whether there was a line terminator in the part we skip.
512 has_line_terminator_before_next_ = false;
513 }
512 Scan(); 514 Scan();
515 ASSERT_EQ(Token::RBRACE, next_.token);
513 } 516 }
514 517
515 518
516 void JavaScriptScanner::ScanEscape() { 519 void JavaScriptScanner::ScanEscape() {
517 uc32 c = c0_; 520 uc32 c = c0_;
518 Advance(); 521 Advance();
519 522
520 // Skip escaped newlines. 523 // Skip escaped newlines.
521 if (ScannerConstants::kIsLineTerminator.get(c)) { 524 if (ScannerConstants::kIsLineTerminator.get(c)) {
522 // Allow CR+LF newlines in multiline string literals. 525 // Allow CR+LF newlines in multiline string literals.
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return; 917 if (MatchKeywordStart(input, "with", 1, Token::WITH)) return;
915 break; 918 break;
916 case UNMATCHABLE: 919 case UNMATCHABLE:
917 break; 920 break;
918 } 921 }
919 // On fallthrough, it's a failure. 922 // On fallthrough, it's a failure.
920 state_ = UNMATCHABLE; 923 state_ = UNMATCHABLE;
921 } 924 }
922 925
923 } } // namespace v8::internal 926 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scanner-base.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698