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

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

Issue 381603002: Address comments on double-parse implementation from earlier CL. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | runtime/vm/object.cc » ('j') | 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 */ factory String.fromCharCode(int charCode) { 10 /* patch */ factory String.fromCharCode(int charCode) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 } 127 }
128 return true; 128 return true;
129 } 129 }
130 130
131 int compareTo(String other) { 131 int compareTo(String other) {
132 int thisLength = this.length; 132 int thisLength = this.length;
133 int otherLength = other.length; 133 int otherLength = other.length;
134 int len = (thisLength < otherLength) ? thisLength : otherLength; 134 int len = (thisLength < otherLength) ? thisLength : otherLength;
135 for (int i = 0; i < len; i++) { 135 for (int i = 0; i < len; i++) {
136 int thisCodePoint = this.codeUnitAt(i); 136 int thisCodeUnit = this.codeUnitAt(i);
137 int otherCodePoint = other.codeUnitAt(i); 137 int otherCodeUnit = other.codeUnitAt(i);
138 if (thisCodePoint < otherCodePoint) { 138 if (thisCodeUnit < otherCodeUnit) {
139 return -1; 139 return -1;
140 } 140 }
141 if (thisCodePoint > otherCodePoint) { 141 if (thisCodeUnit > otherCodeUnit) {
142 return 1; 142 return 1;
143 } 143 }
144 } 144 }
145 if (thisLength < otherLength) return -1; 145 if (thisLength < otherLength) return -1;
146 if (thisLength > otherLength) return 1; 146 if (thisLength > otherLength) return 1;
147 return 0; 147 return 0;
148 } 148 }
149 149
150 bool _substringMatches(int start, String other) { 150 bool _substringMatches(int start, String other) {
151 if (other.isEmpty) return true; 151 if (other.isEmpty) return true;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // 1680 ; White_Space # Zs OGHAM SPACE MARK 273 // 1680 ; White_Space # Zs OGHAM SPACE MARK
274 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR 274 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR
275 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE 275 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE
276 // 2028 ; White_Space # Zl LINE SEPARATOR 276 // 2028 ; White_Space # Zl LINE SEPARATOR
277 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR 277 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR
278 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE 278 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE
279 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE 279 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE
280 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE 280 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE
281 // 281 //
282 // BOM: 0xFEFF 282 // BOM: 0xFEFF
283 static bool _isTwoByteWhitespace(int codePoint) { 283 static bool _isTwoByteWhitespace(int codeUnit) {
284 if (codePoint < 256) return _isOneByteWhitespace(codePoint); 284 if (codeUnit < 256) return _isOneByteWhitespace(codeUnit);
285 return (codePoint == 0x1680) || 285 return (codeUnit == 0x1680) ||
286 (codePoint == 0x180E) || 286 (codeUnit == 0x180E) ||
287 ((0x2000 <= codePoint) && (codePoint <= 0x200A)) || 287 ((0x2000 <= codeUnit) && (codeUnit <= 0x200A)) ||
288 (codePoint == 0x2028) || 288 (codeUnit == 0x2028) ||
289 (codePoint == 0x2029) || 289 (codeUnit == 0x2029) ||
290 (codePoint == 0x202F) || 290 (codeUnit == 0x202F) ||
291 (codePoint == 0x205F) || 291 (codeUnit == 0x205F) ||
292 (codePoint == 0x3000) || 292 (codeUnit == 0x3000) ||
293 (codePoint == 0xFEFF); 293 (codeUnit == 0xFEFF);
294 } 294 }
295 295
296 int _firstNonWhitespace() { 296 int _firstNonWhitespace() {
297 final len = this.length; 297 final len = this.length;
298 int first = 0; 298 int first = 0;
299 for (; first < len; first++) { 299 for (; first < len; first++) {
300 if (!_isWhitespace(this.codeUnitAt(first))) { 300 if (!_isWhitespace(this.codeUnitAt(first))) {
301 break; 301 break;
302 } 302 }
303 } 303 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 636
637 class _OneByteString extends _StringBase implements String { 637 class _OneByteString extends _StringBase implements String {
638 638
639 factory _OneByteString._uninstantiable() { 639 factory _OneByteString._uninstantiable() {
640 throw new UnsupportedError( 640 throw new UnsupportedError(
641 "_OneByteString can only be allocated by the VM"); 641 "_OneByteString can only be allocated by the VM");
642 } 642 }
643 643
644 int get hashCode native "String_getHashCode"; 644 int get hashCode native "String_getHashCode";
645 645
646 bool _isWhitespace(int codePoint) { 646 bool _isWhitespace(int codeUnit) {
647 return _StringBase._isOneByteWhitespace(codePoint); 647 return _StringBase._isOneByteWhitespace(codeUnit);
648 } 648 }
649 649
650 bool operator ==(Object other) { 650 bool operator ==(Object other) {
651 return super == other; 651 return super == other;
652 } 652 }
653 653
654 String _substringUncheckedNative(int startIndex, int endIndex) 654 String _substringUncheckedNative(int startIndex, int endIndex)
655 native "OneByteString_substringUnchecked"; 655 native "OneByteString_substringUnchecked";
656 656
657 List<String> _splitWithCharCode(int charCode) 657 List<String> _splitWithCharCode(int charCode)
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 void _setAt(int index, int codePoint) native "OneByteString_setAt"; 914 void _setAt(int index, int codePoint) native "OneByteString_setAt";
915 } 915 }
916 916
917 917
918 class _TwoByteString extends _StringBase implements String { 918 class _TwoByteString extends _StringBase implements String {
919 factory _TwoByteString._uninstantiable() { 919 factory _TwoByteString._uninstantiable() {
920 throw new UnsupportedError( 920 throw new UnsupportedError(
921 "_TwoByteString can only be allocated by the VM"); 921 "_TwoByteString can only be allocated by the VM");
922 } 922 }
923 923
924 bool _isWhitespace(int codePoint) { 924 bool _isWhitespace(int codeUnit) {
925 return _StringBase._isTwoByteWhitespace(codePoint); 925 return _StringBase._isTwoByteWhitespace(codeUnit);
926 } 926 }
927 927
928 bool operator ==(Object other) { 928 bool operator ==(Object other) {
929 return super == other; 929 return super == other;
930 } 930 }
931 } 931 }
932 932
933 933
934 class _ExternalOneByteString extends _StringBase implements String { 934 class _ExternalOneByteString extends _StringBase implements String {
935 factory _ExternalOneByteString._uninstantiable() { 935 factory _ExternalOneByteString._uninstantiable() {
936 throw new UnsupportedError( 936 throw new UnsupportedError(
937 "_ExternalOneByteString can only be allocated by the VM"); 937 "_ExternalOneByteString can only be allocated by the VM");
938 } 938 }
939 939
940 bool _isWhitespace(int codePoint) { 940 bool _isWhitespace(int codeUnit) {
941 return _StringBase._isOneByteWhitespace(codePoint); 941 return _StringBase._isOneByteWhitespace(codeUnit);
942 } 942 }
943 943
944 bool operator ==(Object other) { 944 bool operator ==(Object other) {
945 return super == other; 945 return super == other;
946 } 946 }
947 947
948 static int _getCid() native "ExternalOneByteString_getCid"; 948 static int _getCid() native "ExternalOneByteString_getCid";
949 } 949 }
950 950
951 951
952 class _ExternalTwoByteString extends _StringBase implements String { 952 class _ExternalTwoByteString extends _StringBase implements String {
953 factory _ExternalTwoByteString._uninstantiable() { 953 factory _ExternalTwoByteString._uninstantiable() {
954 throw new UnsupportedError( 954 throw new UnsupportedError(
955 "_ExternalTwoByteString can only be allocated by the VM"); 955 "_ExternalTwoByteString can only be allocated by the VM");
956 } 956 }
957 957
958 bool _isWhitespace(int codePoint) { 958 bool _isWhitespace(int codeUnit) {
959 return _StringBase._isTwoByteWhitespace(codePoint); 959 return _StringBase._isTwoByteWhitespace(codeUnit);
960 } 960 }
961 961
962 bool operator ==(Object other) { 962 bool operator ==(Object other) {
963 return super == other; 963 return super == other;
964 } 964 }
965 } 965 }
966 966
967 967
968 class _StringMatch implements Match { 968 class _StringMatch implements Match {
969 const _StringMatch(int this.start, 969 const _StringMatch(int this.start,
(...skipping 30 matching lines...) Expand all
1000 class _CodeUnits extends Object with ListMixin<int>, 1000 class _CodeUnits extends Object with ListMixin<int>,
1001 UnmodifiableListMixin<int> { 1001 UnmodifiableListMixin<int> {
1002 /** The string that this is the code units of. */ 1002 /** The string that this is the code units of. */
1003 String _string; 1003 String _string;
1004 1004
1005 _CodeUnits(this._string); 1005 _CodeUnits(this._string);
1006 1006
1007 int get length => _string.length; 1007 int get length => _string.length;
1008 int operator[](int i) => _string.codeUnitAt(i); 1008 int operator[](int i) => _string.codeUnitAt(i);
1009 } 1009 }
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698