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

Side by Side Diff: runtime/lib/string_patch.dart

Issue 398813002: Performance tweak on int.parse. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comment. 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 | « runtime/lib/integers_patch.dart ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 patch class String { 5 patch class String {
6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) {
7 return _StringBase.createFromCharCodes(charCodes); 7 return _StringBase.createFromCharCodes(charCodes);
8 } 8 }
9 9
10 /* patch */ factory String.fromCharCode(int charCode) { 10 /* patch */ factory String.fromCharCode(int charCode) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 return _substringUncheckedNative(startIndex, endIndex); 253 return _substringUncheckedNative(startIndex, endIndex);
254 } 254 }
255 255
256 String _substringUncheckedNative(int startIndex, int endIndex) 256 String _substringUncheckedNative(int startIndex, int endIndex)
257 native "StringBase_substringUnchecked"; 257 native "StringBase_substringUnchecked";
258 258
259 // Checks for one-byte whitespaces only. 259 // Checks for one-byte whitespaces only.
260 static bool _isOneByteWhitespace(int codePoint) { 260 static bool _isOneByteWhitespace(int codePoint) {
261 return 261 return
262 (codePoint == 32) || // Space. 262 (codePoint == 32) || // Space.
263 ((9 <= codePoint) && (codePoint <= 13)) || // CR, LF, TAB, etc. 263 ((codePoint <= 13) ? (9 <= codePoint) // CR, LF, TAB, etc.
264 (codePoint == 0x85) || // NEL 264 : ((codePoint == 0x85) || // NEL
265 (codePoint == 0xA0); // NBSP 265 (codePoint == 0xA0))); // NBSP
266 } 266 }
267 267
268 // Characters with Whitespace property (Unicode 6.2). 268 // Characters with Whitespace property (Unicode 6.2).
269 // 0009..000D ; White_Space # Cc <control-0009>..<control-000D> 269 // 0009..000D ; White_Space # Cc <control-0009>..<control-000D>
270 // 0020 ; White_Space # Zs SPACE 270 // 0020 ; White_Space # Zs SPACE
271 // 0085 ; White_Space # Cc <control-0085> 271 // 0085 ; White_Space # Cc <control-0085>
272 // 00A0 ; White_Space # Zs NO-BREAK SPACE 272 // 00A0 ; White_Space # Zs NO-BREAK SPACE
273 // 1680 ; White_Space # Zs OGHAM SPACE MARK 273 // 1680 ; White_Space # Zs OGHAM SPACE MARK
274 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR 274 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR
275 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE 275 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE
276 // 2028 ; White_Space # Zl LINE SEPARATOR 276 // 2028 ; White_Space # Zl LINE SEPARATOR
277 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR 277 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR
278 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE 278 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE
279 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE 279 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE
280 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE 280 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE
281 // 281 //
282 // BOM: 0xFEFF 282 // BOM: 0xFEFF
283 static bool _isTwoByteWhitespace(int codeUnit) { 283 static bool _isTwoByteWhitespace(int codeUnit) {
284 if (codeUnit < 256) return _isOneByteWhitespace(codeUnit); 284 if (codeUnit <= 0xA0) return _isOneByteWhitespace(codeUnit);
285 return (codeUnit == 0x1680) || 285 return (codeUnit <= 0x200A)
286 (codeUnit == 0x180E) || 286 ? ((codeUnit == 0x1680) ||
287 ((0x2000 <= codeUnit) && (codeUnit <= 0x200A)) || 287 (codeUnit == 0x180E) ||
288 (codeUnit == 0x2028) || 288 (0x2000 <= codeUnit))
289 (codeUnit == 0x2029) || 289 : ((codeUnit == 0x2028) ||
290 (codeUnit == 0x202F) || 290 (codeUnit == 0x2029) ||
291 (codeUnit == 0x205F) || 291 (codeUnit == 0x202F) ||
292 (codeUnit == 0x3000) || 292 (codeUnit == 0x205F) ||
293 (codeUnit == 0xFEFF); 293 (codeUnit == 0x3000) ||
294 (codeUnit == 0xFEFF));
294 } 295 }
295 296
296 int _firstNonWhitespace() { 297 int _firstNonWhitespace() {
297 final len = this.length; 298 final len = this.length;
298 int first = 0; 299 int first = 0;
299 for (; first < len; first++) { 300 for (; first < len; first++) {
300 if (!_isWhitespace(this.codeUnitAt(first))) { 301 if (!_isWhitespace(this.codeUnitAt(first))) {
301 break; 302 break;
302 } 303 }
303 } 304 }
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 class _CodeUnits extends Object with ListMixin<int>, 1001 class _CodeUnits extends Object with ListMixin<int>,
1001 UnmodifiableListMixin<int> { 1002 UnmodifiableListMixin<int> {
1002 /** The string that this is the code units of. */ 1003 /** The string that this is the code units of. */
1003 String _string; 1004 String _string;
1004 1005
1005 _CodeUnits(this._string); 1006 _CodeUnits(this._string);
1006 1007
1007 int get length => _string.length; 1008 int get length => _string.length;
1008 int operator[](int i) => _string.codeUnitAt(i); 1009 int operator[](int i) => _string.codeUnitAt(i);
1009 } 1010 }
OLDNEW
« no previous file with comments | « runtime/lib/integers_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698