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

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

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 | « no previous file | src/parsing/scanner.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 // 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 #ifndef V8_PARSING_SCANNER_H_ 7 #ifndef V8_PARSING_SCANNER_H_
8 #define V8_PARSING_SCANNER_H_ 8 #define V8_PARSING_SCANNER_H_
9 9
10 #include "src/allocation.h" 10 #include "src/allocation.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 static const int kBufferSize = 100; 141 static const int kBufferSize = 100;
142 142
143 UnicodeCache* unicode_constants_; 143 UnicodeCache* unicode_constants_;
144 // Backing store used to store strings used as hashmap keys. 144 // Backing store used to store strings used as hashmap keys.
145 SequenceCollector<unsigned char> backing_store_; 145 SequenceCollector<unsigned char> backing_store_;
146 HashMap map_; 146 HashMap map_;
147 // Buffer used for string->number->canonical string conversions. 147 // Buffer used for string->number->canonical string conversions.
148 char number_buffer_[kBufferSize]; 148 char number_buffer_[kBufferSize];
149 }; 149 };
150 150
151
152 // ---------------------------------------------------------------------------- 151 // ----------------------------------------------------------------------------
153 // LiteralBuffer - Collector of chars of literals. 152 // LiteralBuffer - Collector of chars of literals.
154 153
154 const int kMaxAscii = 127;
155
155 class LiteralBuffer { 156 class LiteralBuffer {
156 public: 157 public:
157 LiteralBuffer() : is_one_byte_(true), position_(0), backing_store_() { } 158 LiteralBuffer() : is_one_byte_(true), position_(0), backing_store_() { }
158 159
159 ~LiteralBuffer() { backing_store_.Dispose(); } 160 ~LiteralBuffer() { backing_store_.Dispose(); }
160 161
161 INLINE(void AddChar(uint32_t code_unit)) { 162 INLINE(void AddChar(char code_unit)) {
163 if (position_ >= backing_store_.length()) ExpandBuffer();
164 DCHECK(is_one_byte_);
165 DCHECK(0 <= code_unit && code_unit <= kMaxAscii);
166 backing_store_[position_] = static_cast<byte>(code_unit);
167 position_ += kOneByteSize;
168 return;
169 }
170
171 INLINE(void AddChar(uc32 code_unit)) {
162 if (position_ >= backing_store_.length()) ExpandBuffer(); 172 if (position_ >= backing_store_.length()) ExpandBuffer();
163 if (is_one_byte_) { 173 if (is_one_byte_) {
164 if (code_unit <= unibrow::Latin1::kMaxChar) { 174 if (code_unit <= unibrow::Latin1::kMaxChar) {
165 backing_store_[position_] = static_cast<byte>(code_unit); 175 backing_store_[position_] = static_cast<byte>(code_unit);
166 position_ += kOneByteSize; 176 position_ += kOneByteSize;
167 return; 177 return;
168 } 178 }
169 ConvertToTwoByte(); 179 ConvertToTwoByte();
170 } 180 }
171 if (code_unit <= unibrow::Utf16::kMaxNonSurrogateCharCode) { 181 if (code_unit <= unibrow::Utf16::kMaxNonSurrogateCharCode) {
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 : &raw_literal_buffer0_; 560 : &raw_literal_buffer0_;
551 free_buffer->Reset(); 561 free_buffer->Reset();
552 next_.raw_literal_chars = free_buffer; 562 next_.raw_literal_chars = free_buffer;
553 } 563 }
554 564
555 INLINE(void AddLiteralChar(uc32 c)) { 565 INLINE(void AddLiteralChar(uc32 c)) {
556 DCHECK_NOT_NULL(next_.literal_chars); 566 DCHECK_NOT_NULL(next_.literal_chars);
557 next_.literal_chars->AddChar(c); 567 next_.literal_chars->AddChar(c);
558 } 568 }
559 569
570 INLINE(void AddLiteralChar(char c)) {
571 DCHECK_NOT_NULL(next_.literal_chars);
572 next_.literal_chars->AddChar(c);
573 }
574
560 INLINE(void AddRawLiteralChar(uc32 c)) { 575 INLINE(void AddRawLiteralChar(uc32 c)) {
561 DCHECK_NOT_NULL(next_.raw_literal_chars); 576 DCHECK_NOT_NULL(next_.raw_literal_chars);
562 next_.raw_literal_chars->AddChar(c); 577 next_.raw_literal_chars->AddChar(c);
563 } 578 }
564 579
565 INLINE(void ReduceRawLiteralLength(int delta)) { 580 INLINE(void ReduceRawLiteralLength(int delta)) {
566 DCHECK_NOT_NULL(next_.raw_literal_chars); 581 DCHECK_NOT_NULL(next_.raw_literal_chars);
567 next_.raw_literal_chars->ReduceLength(delta); 582 next_.raw_literal_chars->ReduceLength(delta);
568 } 583 }
569 584
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 bool allow_harmony_exponentiation_operator_; 822 bool allow_harmony_exponentiation_operator_;
808 823
809 MessageTemplate::Template scanner_error_; 824 MessageTemplate::Template scanner_error_;
810 Location scanner_error_location_; 825 Location scanner_error_location_;
811 }; 826 };
812 827
813 } // namespace internal 828 } // namespace internal
814 } // namespace v8 829 } // namespace v8
815 830
816 #endif // V8_PARSING_SCANNER_H_ 831 #endif // V8_PARSING_SCANNER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parsing/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698