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

Unified Diff: runtime/lib/string_patch.dart

Issue 54503004: Optimize OneByteString’s contains function for one character patterns (similar to indexOf). (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 | « 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_patch.dart
===================================================================
--- runtime/lib/string_patch.dart (revision 29681)
+++ runtime/lib/string_patch.dart (working copy)
@@ -602,6 +602,28 @@
return super.indexOf(pattern, start);
}
+ bool contains(Pattern pattern, [int start = 0]) {
+ 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 false;
+ }
+ for (int i = start; i < len; i++) {
+ if (this.codeUnitAt(i) == patternCu0) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ return super.contains(pattern, start);
+ }
+
// Allocates a string of given length, expecting its content to be
// set using _setAt.
static _OneByteString _allocate(int length) native "OneByteString_allocate";
« 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