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

Unified Diff: runtime/lib/string_base.dart

Issue 11415234: Improve performance of String split (use unchecked substring). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string_base.dart
===================================================================
--- runtime/lib/string_base.dart (revision 15588)
+++ runtime/lib/string_base.dart (working copy)
@@ -53,7 +53,7 @@
}
bool operator ==(Object other) {
- if (this === other) {
+ if (identical(this, other)) {
return true;
}
if ((other is !String) ||
@@ -152,16 +152,25 @@
if (startIndex > endIndex) {
throw new RangeError.value(startIndex);
}
+ return _substringUnchecked(startIndex, endIndex);
+ }
+
+ String _substringUnchecked(int startIndex, int endIndex) {
+ assert(endIndex != null);
+ assert((startIndex >= 0) && (startIndex <= this.length));
+ assert((endIndex >= 0) && (endIndex <= this.length));
+ assert(startIndex <= endIndex);
+
if (startIndex == endIndex) {
return "";
}
if ((startIndex + 1) == endIndex) {
return this[startIndex];
}
- return _substringUnchecked(startIndex, endIndex);
+ return _substringUncheckedNative(startIndex, endIndex);
}
- String _substringUnchecked(int startIndex, int endIndex)
+ String _substringUncheckedNative(int startIndex, int endIndex)
native "StringBase_substringUnchecked";
String trim() {
@@ -283,12 +292,12 @@
int previousIndex = 0;
while (true) {
if (startIndex == length || !iterator.hasNext) {
- result.add(this.substring(previousIndex, length));
+ result.add(this._substringUnchecked(previousIndex, length));
break;
}
Match match = iterator.next();
if (match.start == length) {
- result.add(this.substring(previousIndex, length));
+ result.add(this._substringUnchecked(previousIndex, length));
break;
}
int endIndex = match.end;
@@ -296,7 +305,7 @@
++startIndex; // empty match, advance and restart
continue;
}
- result.add(this.substring(previousIndex, match.start));
+ result.add(this._substringUnchecked(previousIndex, match.start));
startIndex = previousIndex = endIndex;
}
return result;
@@ -378,7 +387,7 @@
((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc.
}
- String _substringUnchecked(int startIndex, int endIndex)
+ String _substringUncheckedNative(int startIndex, int endIndex)
native "OneByteString_substringUnchecked";
}
« 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