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

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

Issue 11416270: Implement faster splitting with empty string as pattern. Add special native for computing substring… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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/string.cc ('k') | runtime/vm/bootstrap_natives.h » ('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 (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 /** 5 /**
6 * [_StringBase] contains common methods used by concrete String 6 * [_StringBase] contains common methods used by concrete String
7 * implementations, e.g., _OneByteString. 7 * implementations, e.g., _OneByteString.
8 */ 8 */
9 class _StringBase { 9 class _StringBase {
10 10
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } else if (position == endIndex) { 262 } else if (position == endIndex) {
263 ++startIndex; // empty match, advance and restart 263 ++startIndex; // empty match, advance and restart
264 } else { 264 } else {
265 startIndex = endIndex; 265 startIndex = endIndex;
266 } 266 }
267 } 267 }
268 return result; 268 return result;
269 } 269 }
270 270
271 List<String> split(Pattern pattern) { 271 List<String> split(Pattern pattern) {
272 if ((pattern is String) && pattern.isEmpty) {
273 return splitChars();
274 }
272 int length = this.length; 275 int length = this.length;
273 Iterator iterator = pattern.allMatches(this).iterator(); 276 Iterator iterator = pattern.allMatches(this).iterator();
274 if (length == 0 && iterator.hasNext) { 277 if (length == 0 && iterator.hasNext) {
275 // A matched empty string input returns the empty list. 278 // A matched empty string input returns the empty list.
276 return <String>[]; 279 return <String>[];
277 } 280 }
278 List<String> result = new List<String>(); 281 List<String> result = new List<String>();
279 int startIndex = 0; 282 int startIndex = 0;
280 int previousIndex = 0; 283 int previousIndex = 0;
281 while (true) { 284 while (true) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 371
369 // Checks for one-byte whitespaces only. 372 // Checks for one-byte whitespaces only.
370 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid 373 // TODO(srdjan): Investigate if 0x85 (NEL) and 0xA0 (NBSP) are valid
371 // whitespaces for one byte strings. 374 // whitespaces for one byte strings.
372 bool _isWhitespace(int codePoint) { 375 bool _isWhitespace(int codePoint) {
373 return 376 return
374 (codePoint == 32) || // Space. 377 (codePoint == 32) || // Space.
375 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. 378 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
376 } 379 }
377 380
381 String _substringUnchecked(int startIndex, int endIndex)
382 native "OneByteString_substringUnchecked";
378 } 383 }
379 384
380 385
381 class _TwoByteString extends _StringBase implements String { 386 class _TwoByteString extends _StringBase implements String {
382 factory _TwoByteString._uninstantiable() { 387 factory _TwoByteString._uninstantiable() {
383 throw new UnsupportedError( 388 throw new UnsupportedError(
384 "_TwoByteString can only be allocated by the VM"); 389 "_TwoByteString can only be allocated by the VM");
385 } 390 }
386 391
387 // Checks for one-byte whitespaces only. 392 // Checks for one-byte whitespaces only.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 for (int g in groups) { 489 for (int g in groups) {
485 result.add(group(g)); 490 result.add(group(g));
486 } 491 }
487 return result; 492 return result;
488 } 493 }
489 494
490 final int start; 495 final int start;
491 final String str; 496 final String str;
492 final String pattern; 497 final String pattern;
493 } 498 }
OLDNEW
« no previous file with comments | « runtime/lib/string.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698