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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 */ const factory String.fromEnvironment(String name, 10 /* patch */ const factory String.fromEnvironment(String name,
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 if (this.codeUnitAt(i) == patternCu0) { 595 if (this.codeUnitAt(i) == patternCu0) {
596 return i; 596 return i;
597 } 597 }
598 } 598 }
599 return -1; 599 return -1;
600 } 600 }
601 } 601 }
602 return super.indexOf(pattern, start); 602 return super.indexOf(pattern, start);
603 } 603 }
604 604
605 bool contains(Pattern pattern, [int start = 0]) {
606 final pCid = pattern._cid;
607 if ((pCid == _OneByteString._classId) ||
608 (pCid == _TwoByteString._classId) ||
609 (pCid == _ExternalOneByteString._classId)) {
610 final len = this.length;
611 if ((pattern.length == 1) && (start >= 0) && (start < len)) {
612 final patternCu0 = pattern.codeUnitAt(0);
613 if (patternCu0 > 0xFF) {
614 return false;
615 }
616 for (int i = start; i < len; i++) {
617 if (this.codeUnitAt(i) == patternCu0) {
618 return true;
619 }
620 }
621 return false;
622 }
623 }
624 return super.contains(pattern, start);
625 }
626
605 // Allocates a string of given length, expecting its content to be 627 // Allocates a string of given length, expecting its content to be
606 // set using _setAt. 628 // set using _setAt.
607 static _OneByteString _allocate(int length) native "OneByteString_allocate"; 629 static _OneByteString _allocate(int length) native "OneByteString_allocate";
608 630
609 // This is internal helper method. Code point value must be a valid 631 // This is internal helper method. Code point value must be a valid
610 // Latin1 value (0..0xFF), index must be valid. 632 // Latin1 value (0..0xFF), index must be valid.
611 void _setAt(int index, int codePoint) native "OneByteString_setAt"; 633 void _setAt(int index, int codePoint) native "OneByteString_setAt";
612 } 634 }
613 635
614 636
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 class _CodeUnits extends Object with ListMixin<int>, 723 class _CodeUnits extends Object with ListMixin<int>,
702 UnmodifiableListMixin<int> { 724 UnmodifiableListMixin<int> {
703 /** The string that this is the code units of. */ 725 /** The string that this is the code units of. */
704 String _string; 726 String _string;
705 727
706 _CodeUnits(this._string); 728 _CodeUnits(this._string);
707 729
708 int get length => _string.length; 730 int get length => _string.length;
709 int operator[](int i) => _string.codeUnitAt(i); 731 int operator[](int i) => _string.codeUnitAt(i);
710 } 732 }
OLDNEW
« 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