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

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

Issue 212163005: Speed up toLowerCase, by manually inlining the upper-case part. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 807 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
808 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 808 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
809 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xd7, 809 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xd7,
810 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xdf, 810 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xdf,
811 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 811 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
812 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 812 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
813 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 813 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
814 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 814 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
815 ]; 815 ];
816 816
817 String _toLowerCaseUpperCaseDetectedAt(int firstUpperCaseIndex) {
818 // String contains upper case characters. Create a new string.
819 final length = this.length;
820 final result = _allocate(length);
821 // First up to firstUpperIndex.
822 int i = 0;
823 for (; i < firstUpperCaseIndex; i++) {
824 result._setAt(i, this.codeUnitAt(i));
825 }
826 for (; i < length; i++) {
827 result._setAt(i, _LC_TABLE[this.codeUnitAt(i)]);
828 }
829 return result;
830 }
831
832 String toLowerCase() { 817 String toLowerCase() {
833 for (int i = 0; i < this.length; i++) { 818 for (int i = 0; i < this.length; i++) {
834 final c = this.codeUnitAt(i); 819 final c = this.codeUnitAt(i);
835 // Ranges: 0x41-0x5a ('A' - 'Z'), 0xc0-0xd6, 0xd8-0xde. 820 if (c == _LC_TABLE[c]) continue;
836 if (c != _LC_TABLE[c]) { 821 // Upper-case character found.
837 return _toLowerCaseUpperCaseDetectedAt(i); 822 final result = _allocate(this.length);
823 for (int j = 0; j < i; j++) {
824 result._setAt(j, this.codeUnitAt(j));
838 } 825 }
826 for (int j = i; j < this.length; j++) {
827 // Ranges: 0x41-0x5a ('A' - 'Z'), 0xc0-0xd6, 0xd8-0xde.
Lasse Reichstein Nielsen 2014/03/26 11:37:51 Maybe move this comment to the table? // Upper-cas
Anders Johnsen 2014/03/26 11:39:12 Done.
828 result._setAt(j, _LC_TABLE[this.codeUnitAt(j)]);
829 }
830 return result;
839 } 831 }
840 return this; 832 return this;
841 } 833 }
842 834
843 // Allocates a string of given length, expecting its content to be 835 // Allocates a string of given length, expecting its content to be
844 // set using _setAt. 836 // set using _setAt.
845 static _OneByteString _allocate(int length) native "OneByteString_allocate"; 837 static _OneByteString _allocate(int length) native "OneByteString_allocate";
846 838
847 839
848 static _OneByteString _allocateFromOneByteList(List<int> list) 840 static _OneByteString _allocateFromOneByteList(List<int> list)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 class _CodeUnits extends Object with ListMixin<int>, 935 class _CodeUnits extends Object with ListMixin<int>,
944 UnmodifiableListMixin<int> { 936 UnmodifiableListMixin<int> {
945 /** The string that this is the code units of. */ 937 /** The string that this is the code units of. */
946 String _string; 938 String _string;
947 939
948 _CodeUnits(this._string); 940 _CodeUnits(this._string);
949 941
950 int get length => _string.length; 942 int get length => _string.length;
951 int operator[](int i) => _string.codeUnitAt(i); 943 int operator[](int i) => _string.codeUnitAt(i);
952 } 944 }
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