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

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
« no previous file with comments | « 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 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // can be reported later (in strict mode). 832 // can be reported later (in strict mode).
833 // We don't report the error immediately, because the octal escape can 833 // We don't report the error immediately, because the octal escape can
834 // occur before the "use strict" directive. 834 // occur before the "use strict" directive.
835 if (c != '0' || i > 0) { 835 if (c != '0' || i > 0) {
836 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1); 836 octal_pos_ = Location(source_pos() - i - 1, source_pos() - 1);
837 } 837 }
838 return x; 838 return x;
839 } 839 }
840 840
841 841
842 const int kMaxAscii = 127;
843
844
845 Token::Value Scanner::ScanString() { 842 Token::Value Scanner::ScanString() {
846 uc32 quote = c0_; 843 uc32 quote = c0_;
847 Advance<false, false>(); // consume quote 844 Advance<false, false>(); // consume quote
848 845
849 LiteralScope literal(this); 846 LiteralScope literal(this);
850 while (true) { 847 while (true) {
851 if (c0_ > kMaxAscii) { 848 if (c0_ > kMaxAscii) {
852 HandleLeadSurrogate(); 849 HandleLeadSurrogate();
853 break; 850 break;
854 } 851 }
855 if (c0_ < 0 || c0_ == '\n' || c0_ == '\r') return Token::ILLEGAL; 852 if (c0_ < 0 || c0_ == '\n' || c0_ == '\r') return Token::ILLEGAL;
856 if (c0_ == quote) { 853 if (c0_ == quote) {
857 literal.Complete(); 854 literal.Complete();
858 Advance<false, false>(); 855 Advance<false, false>();
859 return Token::STRING; 856 return Token::STRING;
860 } 857 }
861 uc32 c = c0_; 858 char c = static_cast<char>(c0_);
862 if (c == '\\') break; 859 if (c == '\\') break;
863 Advance<false, false>(); 860 Advance<false, false>();
864 AddLiteralChar(c); 861 AddLiteralChar(c);
865 } 862 }
866 863
867 while (c0_ != quote && c0_ >= 0 864 while (c0_ != quote && c0_ >= 0
868 && !unicode_cache_->IsLineTerminator(c0_)) { 865 && !unicode_cache_->IsLineTerminator(c0_)) {
869 uc32 c = c0_; 866 uc32 c = c0_;
870 Advance(); 867 Advance();
871 if (c == '\\') { 868 if (c == '\\') {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 return Token::FUTURE_STRICT_RESERVED_WORD == 1273 return Token::FUTURE_STRICT_RESERVED_WORD ==
1277 KeywordOrIdentifierToken(string->raw_data(), string->length(), false); 1274 KeywordOrIdentifierToken(string->raw_data(), string->length(), false);
1278 } 1275 }
1279 1276
1280 1277
1281 Token::Value Scanner::ScanIdentifierOrKeyword() { 1278 Token::Value Scanner::ScanIdentifierOrKeyword() {
1282 DCHECK(unicode_cache_->IsIdentifierStart(c0_)); 1279 DCHECK(unicode_cache_->IsIdentifierStart(c0_));
1283 LiteralScope literal(this); 1280 LiteralScope literal(this);
1284 if (IsInRange(c0_, 'a', 'z')) { 1281 if (IsInRange(c0_, 'a', 'z')) {
1285 do { 1282 do {
1286 uc32 first_char = c0_; 1283 char first_char = static_cast<char>(c0_);
1287 Advance<false, false>(); 1284 Advance<false, false>();
1288 AddLiteralChar(first_char); 1285 AddLiteralChar(first_char);
1289 } while (IsInRange(c0_, 'a', 'z')); 1286 } while (IsInRange(c0_, 'a', 'z'));
1290 1287
1291 if (IsDecimalDigit(c0_) || IsInRange(c0_, 'A', 'Z') || c0_ == '_' || 1288 if (IsDecimalDigit(c0_) || IsInRange(c0_, 'A', 'Z') || c0_ == '_' ||
1292 c0_ == '$') { 1289 c0_ == '$') {
1293 // Identifier starting with lowercase. 1290 // Identifier starting with lowercase.
1294 uc32 first_char = c0_; 1291 char first_char = static_cast<char>(c0_);
1295 Advance<false, false>(); 1292 Advance<false, false>();
1296 AddLiteralChar(first_char); 1293 AddLiteralChar(first_char);
1297 while (IsAsciiIdentifier(c0_)) { 1294 while (IsAsciiIdentifier(c0_)) {
1298 uc32 first_char = c0_; 1295 char first_char = static_cast<char>(c0_);
1299 Advance<false, false>(); 1296 Advance<false, false>();
1300 AddLiteralChar(first_char); 1297 AddLiteralChar(first_char);
1301 } 1298 }
1302 if (c0_ <= kMaxAscii && c0_ != '\\') { 1299 if (c0_ <= kMaxAscii && c0_ != '\\') {
1303 literal.Complete(); 1300 literal.Complete();
1304 return Token::IDENTIFIER; 1301 return Token::IDENTIFIER;
1305 } 1302 }
1306 } else if (c0_ <= kMaxAscii && c0_ != '\\') { 1303 } else if (c0_ <= kMaxAscii && c0_ != '\\') {
1307 // Only a-z+: could be a keyword or identifier. 1304 // Only a-z+: could be a keyword or identifier.
1308 literal.Complete(); 1305 literal.Complete();
1309 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal(); 1306 Vector<const uint8_t> chars = next_.literal_chars->one_byte_literal();
1310 return KeywordOrIdentifierToken(chars.start(), chars.length(), false); 1307 return KeywordOrIdentifierToken(chars.start(), chars.length(), false);
1311 } 1308 }
1312 1309
1313 HandleLeadSurrogate(); 1310 HandleLeadSurrogate();
1314 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') { 1311 } else if (IsInRange(c0_, 'A', 'Z') || c0_ == '_' || c0_ == '$') {
1315 do { 1312 do {
1316 uc32 first_char = c0_; 1313 char first_char = static_cast<char>(c0_);
1317 Advance<false, false>(); 1314 Advance<false, false>();
1318 AddLiteralChar(first_char); 1315 AddLiteralChar(first_char);
1319 } while (IsAsciiIdentifier(c0_)); 1316 } while (IsAsciiIdentifier(c0_));
1320 1317
1321 if (c0_ <= kMaxAscii && c0_ != '\\') { 1318 if (c0_ <= kMaxAscii && c0_ != '\\') {
1322 literal.Complete(); 1319 literal.Complete();
1323 return Token::IDENTIFIER; 1320 return Token::IDENTIFIER;
1324 } 1321 }
1325 1322
1326 HandleLeadSurrogate(); 1323 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)); 1706 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u));
1710 } 1707 }
1711 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); 1708 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f));
1712 1709
1713 backing_store_.AddBlock(bytes); 1710 backing_store_.AddBlock(bytes);
1714 return backing_store_.EndSequence().start(); 1711 return backing_store_.EndSequence().start();
1715 } 1712 }
1716 1713
1717 } // namespace internal 1714 } // namespace internal
1718 } // namespace v8 1715 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/scanner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698