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

Side by Side Diff: src/scanner-character-streams.cc

Issue 381613003: Parser / Scanner: Minor refactorings to make streaming scripts work easier. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/scanner-character-streams.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 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/scanner-character-streams.h" 7 #include "src/scanner-character-streams.h"
8 8
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/unicode-inl.h" 10 #include "src/unicode-inl.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 buffer_cursor_ = buffer_; 71 buffer_cursor_ = buffer_;
72 if (pushback_limit_ != NULL) { 72 if (pushback_limit_ != NULL) {
73 // Leave pushback mode. 73 // Leave pushback mode.
74 buffer_end_ = pushback_limit_; 74 buffer_end_ = pushback_limit_;
75 pushback_limit_ = NULL; 75 pushback_limit_ = NULL;
76 // If there were any valid characters left at the 76 // If there were any valid characters left at the
77 // start of the buffer, use those. 77 // start of the buffer, use those.
78 if (buffer_cursor_ < buffer_end_) return true; 78 if (buffer_cursor_ < buffer_end_) return true;
79 // Otherwise read a new block. 79 // Otherwise read a new block.
80 } 80 }
81 unsigned length = FillBuffer(pos_, kBufferSize); 81 unsigned length = FillBuffer(pos_);
82 buffer_end_ = buffer_ + length; 82 buffer_end_ = buffer_ + length;
83 return length > 0; 83 return length > 0;
84 } 84 }
85 85
86 86
87 unsigned BufferedUtf16CharacterStream::SlowSeekForward(unsigned delta) { 87 unsigned BufferedUtf16CharacterStream::SlowSeekForward(unsigned delta) {
88 // Leave pushback mode (i.e., ignore that there might be valid data 88 // Leave pushback mode (i.e., ignore that there might be valid data
89 // in the buffer before the pushback_limit_ point). 89 // in the buffer before the pushback_limit_ point).
90 pushback_limit_ = NULL; 90 pushback_limit_ = NULL;
91 return BufferSeekForward(delta); 91 return BufferSeekForward(delta);
(...skipping 19 matching lines...) Expand all
111 111
112 112
113 unsigned GenericStringUtf16CharacterStream::BufferSeekForward(unsigned delta) { 113 unsigned GenericStringUtf16CharacterStream::BufferSeekForward(unsigned delta) {
114 unsigned old_pos = pos_; 114 unsigned old_pos = pos_;
115 pos_ = Min(pos_ + delta, length_); 115 pos_ = Min(pos_ + delta, length_);
116 ReadBlock(); 116 ReadBlock();
117 return pos_ - old_pos; 117 return pos_ - old_pos;
118 } 118 }
119 119
120 120
121 unsigned GenericStringUtf16CharacterStream::FillBuffer(unsigned from_pos, 121 unsigned GenericStringUtf16CharacterStream::FillBuffer(unsigned from_pos) {
122 unsigned length) {
123 if (from_pos >= length_) return 0; 122 if (from_pos >= length_) return 0;
123 unsigned length = kBufferSize;
124 if (from_pos + length > length_) { 124 if (from_pos + length > length_) {
125 length = length_ - from_pos; 125 length = length_ - from_pos;
126 } 126 }
127 String::WriteToFlat<uc16>(*string_, buffer_, from_pos, from_pos + length); 127 String::WriteToFlat<uc16>(*string_, buffer_, from_pos, from_pos + length);
128 return length; 128 return length;
129 } 129 }
130 130
131 131
132 // ---------------------------------------------------------------------------- 132 // ----------------------------------------------------------------------------
133 // Utf8ToUtf16CharacterStream 133 // Utf8ToUtf16CharacterStream
(...skipping 14 matching lines...) Expand all
148 unsigned Utf8ToUtf16CharacterStream::BufferSeekForward(unsigned delta) { 148 unsigned Utf8ToUtf16CharacterStream::BufferSeekForward(unsigned delta) {
149 unsigned old_pos = pos_; 149 unsigned old_pos = pos_;
150 unsigned target_pos = pos_ + delta; 150 unsigned target_pos = pos_ + delta;
151 SetRawPosition(target_pos); 151 SetRawPosition(target_pos);
152 pos_ = raw_character_position_; 152 pos_ = raw_character_position_;
153 ReadBlock(); 153 ReadBlock();
154 return pos_ - old_pos; 154 return pos_ - old_pos;
155 } 155 }
156 156
157 157
158 unsigned Utf8ToUtf16CharacterStream::FillBuffer(unsigned char_position, 158 unsigned Utf8ToUtf16CharacterStream::FillBuffer(unsigned char_position) {
159 unsigned length) {
160 static const unibrow::uchar kMaxUtf16Character = 0xffff; 159 static const unibrow::uchar kMaxUtf16Character = 0xffff;
161 SetRawPosition(char_position); 160 SetRawPosition(char_position);
162 if (raw_character_position_ != char_position) { 161 if (raw_character_position_ != char_position) {
163 // char_position was not a valid position in the stream (hit the end 162 // char_position was not a valid position in the stream (hit the end
164 // while spooling to it). 163 // while spooling to it).
165 return 0u; 164 return 0u;
166 } 165 }
167 unsigned i = 0; 166 unsigned i = 0;
168 while (i < length - 1) { 167 while (i < kBufferSize - 1) {
169 if (raw_data_pos_ == raw_data_length_) break; 168 if (raw_data_pos_ == raw_data_length_) break;
170 unibrow::uchar c = raw_data_[raw_data_pos_]; 169 unibrow::uchar c = raw_data_[raw_data_pos_];
171 if (c <= unibrow::Utf8::kMaxOneByteChar) { 170 if (c <= unibrow::Utf8::kMaxOneByteChar) {
172 raw_data_pos_++; 171 raw_data_pos_++;
173 } else { 172 } else {
174 c = unibrow::Utf8::CalculateValue(raw_data_ + raw_data_pos_, 173 c = unibrow::Utf8::CalculateValue(raw_data_ + raw_data_pos_,
175 raw_data_length_ - raw_data_pos_, 174 raw_data_length_ - raw_data_pos_,
176 &raw_data_pos_); 175 &raw_data_pos_);
177 } 176 }
178 if (c > kMaxUtf16Character) { 177 if (c > kMaxUtf16Character) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 int end_position) 290 int end_position)
292 : Utf16CharacterStream(), 291 : Utf16CharacterStream(),
293 source_(data), 292 source_(data),
294 raw_data_(data->GetTwoByteData(start_position)) { 293 raw_data_(data->GetTwoByteData(start_position)) {
295 buffer_cursor_ = raw_data_, 294 buffer_cursor_ = raw_data_,
296 buffer_end_ = raw_data_ + (end_position - start_position); 295 buffer_end_ = raw_data_ + (end_position - start_position);
297 pos_ = start_position; 296 pos_ = start_position;
298 } 297 }
299 298
300 } } // namespace v8::internal 299 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scanner-character-streams.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698