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

Unified Diff: runtime/lib/string_patch.dart

Issue 47073009: Improve indexOf for one byte string receiver to work with other string classes. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/string.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string_patch.dart
===================================================================
--- runtime/lib/string_patch.dart (revision 29605)
+++ runtime/lib/string_patch.dart (working copy)
@@ -136,7 +136,7 @@
}
bool startsWith(Pattern pattern, [int index = 0]) {
- if (index < 0 || index > this.length) {
+ if ((index < 0) || (index > this.length)) {
throw new RangeError.range(index, 0, this.length);
}
if (pattern is String) {
@@ -146,7 +146,7 @@
}
int indexOf(Pattern pattern, [int start = 0]) {
- if (start < 0 || start > this.length) {
+ if ((start < 0) || (start > this.length)) {
throw new RangeError.range(start, 0, this.length);
}
if (pattern is String) {
@@ -576,19 +576,24 @@
}
int indexOf(Pattern pattern, [int start = 0]) {
- final len = this.length;
// Specialize for single character pattern.
- // TODO(srdjan): Implement for other string classes.
- if ((pattern._cid == _OneByteString._classId) &&
- (pattern.length == 1) &&
- (start >= 0) && (start < len)) {
- final patternCu0 = pattern.codeUnitAt(0);
- for (int i = start; i < len; i++) {
- if (this.codeUnitAt(i) == patternCu0) {
- return i;
+ final pCid = pattern._cid;
+ if ((pCid == _OneByteString._classId) ||
+ (pCid == _TwoByteString._classId) ||
+ (pCid == _ExternalOneByteString._classId)) {
+ final len = this.length;
+ if ((pattern.length == 1) && (start >= 0) && (start < len)) {
+ final patternCu0 = pattern.codeUnitAt(0);
+ if (patternCu0 > 0xFF) {
+ return -1;
}
+ for (int i = start; i < len; i++) {
+ if (this.codeUnitAt(i) == patternCu0) {
+ return i;
+ }
+ }
+ return -1;
}
- return -1;
}
return super.indexOf(pattern, start);
}
@@ -604,6 +609,8 @@
class _TwoByteString extends _StringBase implements String {
+ static final int _classId = "\u{FFFF}"._cid;
+
factory _TwoByteString._uninstantiable() {
throw new UnsupportedError(
"_TwoByteString can only be allocated by the VM");
@@ -620,6 +627,8 @@
class _ExternalOneByteString extends _StringBase implements String {
+ static final int _classId = _getCid();
+
factory _ExternalOneByteString._uninstantiable() {
throw new UnsupportedError(
"_ExternalOneByteString can only be allocated by the VM");
@@ -632,6 +641,8 @@
bool operator ==(Object other) {
return super == other;
}
+
+ static int _getCid() native "ExternalOneByteString_getCid";
}
« 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