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

Side by Side Diff: src/parsing/scanner.cc

Issue 2044233004: Speed up adding literal chars when the buffer is known to be one-byte (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 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
« src/parsing/scanner.h ('K') | « src/parsing/scanner.h ('k') | 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Features shared by parsing and pre-parsing scanners. 5 // Features shared by parsing and pre-parsing scanners.
6 6
7 #include "src/parsing/scanner.h" 7 #include "src/parsing/scanner.h"
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 if (c0_ > kMaxAscii) { 851 if (c0_ > kMaxAscii) {
852 HandleLeadSurrogate(); 852 HandleLeadSurrogate();
853 break; 853 break;
854 } 854 }
855 if (c0_ < 0 || c0_ == '\n' || c0_ == '\r') return Token::ILLEGAL; 855 if (c0_ < 0 || c0_ == '\n' || c0_ == '\r') return Token::ILLEGAL;
856 if (c0_ == quote) { 856 if (c0_ == quote) {
857 literal.Complete(); 857 literal.Complete();
858 Advance<false, false>(); 858 Advance<false, false>();
859 return Token::STRING; 859 return Token::STRING;
860 } 860 }
861 uc32 c = c0_; 861 char c = static_cast<char>(c0_);
862 if (c == '\\') break; 862 if (c == '\\') break;
863 Advance<false, false>(); 863 Advance<false, false>();
864 AddLiteralChar(c); 864 AddLiteralChar(c);
865 } 865 }
866 866
867 while (c0_ != quote && c0_ >= 0 867 while (c0_ != quote && c0_ >= 0
868 && !unicode_cache_->IsLineTerminator(c0_)) { 868 && !unicode_cache_->IsLineTerminator(c0_)) {
869 uc32 c = c0_; 869 uc32 c = c0_;
870 Advance(); 870 Advance();
871 if (c == '\\') { 871 if (c == '\\') {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 return Token::FUTURE_STRICT_RESERVED_WORD == 1276 return Token::FUTURE_STRICT_RESERVED_WORD ==
1277 KeywordOrIdentifierToken(string->raw_data(), string->length(), false); 1277 KeywordOrIdentifierToken(string->raw_data(), string->length(), false);
1278 } 1278 }
1279 1279
1280 1280
1281 Token::Value Scanner::ScanIdentifierOrKeyword() { 1281 Token::Value Scanner::ScanIdentifierOrKeyword() {
1282 DCHECK(unicode_cache_->IsIdentifierStart(c0_)); 1282 DCHECK(unicode_cache_->IsIdentifierStart(c0_));
1283 LiteralScope literal(this); 1283 LiteralScope literal(this);
1284 if (IsInRange(c0_, 'a', 'z')) { 1284 if (IsInRange(c0_, 'a', 'z')) {
1285 do { 1285 do {
1286 uc32 first_char = c0_; 1286 char first_char = static_cast<char>(c0_);
1287 Advance<false, false>(); 1287 Advance<false, false>();
1288 AddLiteralChar(first_char); 1288 AddLiteralChar(first_char);
1289 } while (IsInRange(c0_, 'a', 'z')); 1289 } while (IsInRange(c0_, 'a', 'z'));
1290 1290
1291 if (IsDecimalDigit(c0_) || IsInRange(c0_, 'A', 'Z') || c0_ == '_' || 1291 if (IsDecimalDigit(c0_) || IsInRange(c0_, 'A', 'Z') || c0_ == '_' ||
1292 c0_ == '$') { 1292 c0_ == '$') {
1293 // Identifier starting with lowercase. 1293 // Identifier starting with lowercase.
1294 uc32 first_char = c0_; 1294 char first_char = static_cast<char>(c0_);
1295 Advance<false, false>(); 1295 Advance<false, false>();
1296 AddLiteralChar(first_char); 1296 AddLiteralChar(first_char);
1297 while (IsAsciiIdentifier(c0_)) { 1297 while (IsAsciiIdentifier(c0_)) {
1298 uc32 first_char = c0_; 1298 char first_char = static_cast<char>(c0_);
1299 Advance<false, false>(); 1299 Advance<false, false>();
1300 AddLiteralChar(first_char); 1300 AddLiteralChar(first_char);
1301 } 1301 }
1302 if (c0_ <= kMaxAscii && c0_ != '\\') { 1302 if (c0_ <= kMaxAscii && c0_ != '\\') {
1303 literal.Complete(); 1303 literal.Complete();
1304 return Token::IDENTIFIER; 1304 return Token::IDENTIFIER;
1305 } 1305 }
1306 } else if (c0_ <= kMaxAscii && c0_ != '\\') { 1306 } else if (c0_ <= kMaxAscii && c0_ != '\\') {
1307 // Only a-z+: could be a keyword or identifier. 1307 // Only a-z+: could be a keyword or identifier.
1308 literal.Complete(); 1308 literal.Complete();
1309 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); 1309 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
1310 return KeywordOrIdentifierToken(chars.start(), chars.length(), false); 1310 return KeywordOrIdentifierToken(chars.start(), chars.length(), false);
1311 } 1311 }
1312 1312
1313 HandleLeadSurrogate(); 1313 HandleLeadSurrogate();
1314 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { 1314 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') {
1315 do { 1315 do {
1316 uc32 first_char = c0_; 1316 char first_char = static_cast<char>(c0_);
1317 Advance<false, false>(); 1317 Advance<false, false>();
1318 AddLiteralChar(first_char); 1318 AddLiteralChar(first_char);
1319 } while (IsAsciiIdentifier(c0_)); 1319 } while (IsAsciiIdentifier(c0_));
1320 1320
1321 if (c0_ <= kMaxAscii && c0_ != '\\') { 1321 if (c0_ <= kMaxAscii && c0_ != '\\') {
1322 literal.Complete(); 1322 literal.Complete();
1323 return Token::IDENTIFIER; 1323 return Token::IDENTIFIER;
1324 } 1324 }
1325 1325
1326 HandleLeadSurrogate(); 1326 HandleLeadSurrogate();
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); 1709 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1710 } 1710 }
1711 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1711 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1712 1712
1713 backing_store_.AddBlock(bytes); 1713 backing_store_.AddBlock(bytes);
1714 return backing_store_.EndSequence().start(); 1714 return backing_store_.EndSequence().start();
1715 } 1715 }
1716 1716
1717 } // namespace internal 1717 } // namespace internal
1718 } // namespace v8 1718 } // namespace v8
OLDNEW
« src/parsing/scanner.h ('K') | « src/parsing/scanner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698