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

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

Issue 539153002: Port and integrate the irregexp engine from V8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Port remaining V8 regexp tests and fix exposed bugs. Created 6 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 unified diff | Download patch | Annotate | Revision Log
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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 native "OneByteString_splitWithCharCode"; 676 native "OneByteString_splitWithCharCode";
677 677
678 List<String> split(Pattern pattern) { 678 List<String> split(Pattern pattern) {
679 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) && 679 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) &&
680 (pattern.length == 1)) { 680 (pattern.length == 1)) {
681 return _splitWithCharCode(pattern.codeUnitAt(0)); 681 return _splitWithCharCode(pattern.codeUnitAt(0));
682 } 682 }
683 return super.split(pattern); 683 return super.split(pattern);
684 } 684 }
685 685
686 // The codeUnitsAt family of functions is inlined to an unchecked
687 // LoadCodeUnitsInstr, therefore `this` must be a valid string, and `index`
688 // must be in bounds.
689 int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1);
690 int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2);
691 int _fourCodeUnitsAt(int index) => _codeUnitsAt(index, 4);
692
693 // Loads up to 4 code units into a single integer.
694 int _codeUnitsAt(int index, int count) {
695 assert(index >= 0);
696 assert(index + count - 1 < this.length);
697 assert(0 < count && count <= 4);
698
699 int codeUnits = 0;
700 for (int i = 0; i < count; i++) {
701 codeUnits |= this.codeUnitAt(index + i) << (i * 8);
702 }
703
704 return codeUnits;
705 }
706
686 // All element of 'strings' must be OneByteStrings. 707 // All element of 'strings' must be OneByteStrings.
687 static _concatAll(List<String> strings, int totalLength) { 708 static _concatAll(List<String> strings, int totalLength) {
688 // TODO(srdjan): Improve code below and raise or eliminate the limit. 709 // TODO(srdjan): Improve code below and raise or eliminate the limit.
689 if (totalLength > 128) { 710 if (totalLength > 128) {
690 // Native is quicker. 711 // Native is quicker.
691 return _StringBase._concatRangeNative(strings, 0, strings.length); 712 return _StringBase._concatRangeNative(strings, 0, strings.length);
692 } 713 }
693 var res = _OneByteString._allocate(totalLength); 714 var res = _OneByteString._allocate(totalLength);
694 final stringsLength = strings.length; 715 final stringsLength = strings.length;
695 int rIx = 0; 716 int rIx = 0;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 "_TwoByteString can only be allocated by the VM"); 960 "_TwoByteString can only be allocated by the VM");
940 } 961 }
941 962
942 bool _isWhitespace(int codeUnit) { 963 bool _isWhitespace(int codeUnit) {
943 return _StringBase._isTwoByteWhitespace(codeUnit); 964 return _StringBase._isTwoByteWhitespace(codeUnit);
944 } 965 }
945 966
946 bool operator ==(Object other) { 967 bool operator ==(Object other) {
947 return super == other; 968 return super == other;
948 } 969 }
970
971 int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1);
972 int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2);
973
974 // Loads up to 2 code units into a single integer.
975 int _codeUnitsAt(int index, int count) {
976 assert(index >= 0);
977 assert(index + count - 1 < this.length);
978 assert(0 < count && count <= 2);
979
980 int codeUnits = 0;
981 for (int i = 0; i < count; i++) {
982 codeUnits |= this.codeUnitAt(index + i) << (i * 16);
983 }
984
985 return codeUnits;
986 }
949 } 987 }
950 988
951 989
952 class _ExternalOneByteString extends _StringBase implements String { 990 class _ExternalOneByteString extends _StringBase implements String {
953 factory _ExternalOneByteString._uninstantiable() { 991 factory _ExternalOneByteString._uninstantiable() {
954 throw new UnsupportedError( 992 throw new UnsupportedError(
955 "_ExternalOneByteString can only be allocated by the VM"); 993 "_ExternalOneByteString can only be allocated by the VM");
956 } 994 }
957 995
958 bool _isWhitespace(int codeUnit) { 996 bool _isWhitespace(int codeUnit) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 class _CodeUnits extends Object with ListMixin<int>, 1056 class _CodeUnits extends Object with ListMixin<int>,
1019 UnmodifiableListMixin<int> { 1057 UnmodifiableListMixin<int> {
1020 /** The string that this is the code units of. */ 1058 /** The string that this is the code units of. */
1021 String _string; 1059 String _string;
1022 1060
1023 _CodeUnits(this._string); 1061 _CodeUnits(this._string);
1024 1062
1025 int get length => _string.length; 1063 int get length => _string.length;
1026 int operator[](int i) => _string.codeUnitAt(i); 1064 int operator[](int i) => _string.codeUnitAt(i);
1027 } 1065 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698