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

Side by Side Diff: pkg/analyzer/lib/src/dart/scanner/reader.dart

Issue 1935733002: Small improvement to scanner performance (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 | 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 (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.dart.scanner.reader; 5 library analyzer.src.dart.scanner.reader;
6 6
7 /** 7 /**
8 * A [CharacterReader] that reads a range of characters from another character 8 * A [CharacterReader] that reads a range of characters from another character
9 * reader. 9 * reader.
10 */ 10 */
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 */ 102 */
103 class CharSequenceReader implements CharacterReader { 103 class CharSequenceReader implements CharacterReader {
104 /** 104 /**
105 * The sequence from which characters will be read. 105 * The sequence from which characters will be read.
106 */ 106 */
107 final String _sequence; 107 final String _sequence;
108 108
109 /** 109 /**
110 * The number of characters in the string. 110 * The number of characters in the string.
111 */ 111 */
112 int _stringLength = 0; 112 int _stringLength;
113 113
114 /** 114 /**
115 * The index, relative to the string, of the last character that was read. 115 * The index, relative to the string, of the next character to be read.
116 */ 116 */
117 int _charOffset = 0; 117 int _charOffset;
118 118
119 /** 119 /**
120 * Initialize a newly created reader to read the characters in the given 120 * Initialize a newly created reader to read the characters in the given
121 * [_sequence]. 121 * [_sequence].
122 */ 122 */
123 CharSequenceReader(this._sequence) { 123 CharSequenceReader(this._sequence) {
124 this._stringLength = _sequence.length; 124 this._stringLength = _sequence.length;
125 this._charOffset = -1; 125 this._charOffset = 0;
126 } 126 }
127 127
128 @override 128 @override
129 int get offset => _charOffset; 129 int get offset => _charOffset - 1;
130 130
131 @override 131 @override
132 void set offset(int offset) { 132 void set offset(int offset) {
133 _charOffset = offset; 133 _charOffset = offset + 1;
134 } 134 }
135 135
136 @override 136 @override
137 int advance() { 137 int advance() {
138 if (_charOffset + 1 >= _stringLength) { 138 if (_charOffset >= _stringLength) {
139 return -1; 139 return -1;
140 } 140 }
141 return _sequence.codeUnitAt(++_charOffset); 141 return _sequence.codeUnitAt(_charOffset++);
142 } 142 }
143 143
144 @override 144 @override
145 String getString(int start, int endDelta) => 145 String getString(int start, int endDelta) =>
146 _sequence.substring(start, _charOffset + 1 + endDelta).toString(); 146 _sequence.substring(start, _charOffset + endDelta).toString();
147 147
148 @override 148 @override
149 int peek() { 149 int peek() {
150 if (_charOffset + 1 >= _stringLength) { 150 if (_charOffset >= _stringLength) {
151 return -1; 151 return -1;
152 } 152 }
153 return _sequence.codeUnitAt(_charOffset + 1); 153 return _sequence.codeUnitAt(_charOffset);
154 } 154 }
155 } 155 }
156 156
157 /** 157 /**
158 * A [CharacterReader] that reads characters from a character sequence, but adds 158 * A [CharacterReader] that reads characters from a character sequence, but adds
159 * a delta when reporting the current character offset so that the character 159 * a delta when reporting the current character offset so that the character
160 * sequence can be a subsequence from a larger sequence. 160 * sequence can be a subsequence from a larger sequence.
161 */ 161 */
162 class SubSequenceReader extends CharSequenceReader { 162 class SubSequenceReader extends CharSequenceReader {
163 /** 163 /**
(...skipping 14 matching lines...) Expand all
178 178
179 @override 179 @override
180 void set offset(int offset) { 180 void set offset(int offset) {
181 super.offset = offset - _offsetDelta; 181 super.offset = offset - _offsetDelta;
182 } 182 }
183 183
184 @override 184 @override
185 String getString(int start, int endDelta) => 185 String getString(int start, int endDelta) =>
186 super.getString(start - _offsetDelta, endDelta); 186 super.getString(start - _offsetDelta, endDelta);
187 } 187 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698