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

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: Addressed Ivan's comments. 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
« no previous file with comments | « runtime/lib/regexp_patch.dart ('k') | runtime/vm/compiler.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 [int start = 0, int end]) { 7 [int start = 0, int end]) {
8 return _StringBase.createFromCharCodes(charCodes, start, end); 8 return _StringBase.createFromCharCodes(charCodes, start, end);
9 } 9 }
10 10
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 native "OneByteString_splitWithCharCode"; 732 native "OneByteString_splitWithCharCode";
733 733
734 List<String> split(Pattern pattern) { 734 List<String> split(Pattern pattern) {
735 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) && 735 if ((ClassID.getID(pattern) == ClassID.cidOneByteString) &&
736 (pattern.length == 1)) { 736 (pattern.length == 1)) {
737 return _splitWithCharCode(pattern.codeUnitAt(0)); 737 return _splitWithCharCode(pattern.codeUnitAt(0));
738 } 738 }
739 return super.split(pattern); 739 return super.split(pattern);
740 } 740 }
741 741
742 // The codeUnitsAt family of functions is inlined to an unchecked
743 // LoadCodeUnitsInstr, therefore `this` must be a valid string, and `index`
744 // must be in bounds.
745 int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1);
746 int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2);
747 int _fourCodeUnitsAt(int index) => _codeUnitsAt(index, 4);
748
749 // Loads up to 4 code units into a single integer.
750 int _codeUnitsAt(int index, int count) {
751 assert(index >= 0);
752 assert(index + count - 1 < this.length);
753 assert(0 < count && count <= 4);
754
755 int codeUnits = 0;
756 for (int i = 0; i < count; i++) {
757 codeUnits |= this.codeUnitAt(index + i) << (i * 8);
758 }
759
760 return codeUnits;
761 }
762
742 // All element of 'strings' must be OneByteStrings. 763 // All element of 'strings' must be OneByteStrings.
743 static _concatAll(List<String> strings, int totalLength) { 764 static _concatAll(List<String> strings, int totalLength) {
744 // TODO(srdjan): Improve code below and raise or eliminate the limit. 765 // TODO(srdjan): Improve code below and raise or eliminate the limit.
745 if (totalLength > 128) { 766 if (totalLength > 128) {
746 // Native is quicker. 767 // Native is quicker.
747 return _StringBase._concatRangeNative(strings, 0, strings.length); 768 return _StringBase._concatRangeNative(strings, 0, strings.length);
748 } 769 }
749 final res = _OneByteString._allocate(totalLength); 770 final res = _OneByteString._allocate(totalLength);
750 final stringsLength = strings.length; 771 final stringsLength = strings.length;
751 int rIx = 0; 772 int rIx = 0;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 "_TwoByteString can only be allocated by the VM"); 1017 "_TwoByteString can only be allocated by the VM");
997 } 1018 }
998 1019
999 bool _isWhitespace(int codeUnit) { 1020 bool _isWhitespace(int codeUnit) {
1000 return _StringBase._isTwoByteWhitespace(codeUnit); 1021 return _StringBase._isTwoByteWhitespace(codeUnit);
1001 } 1022 }
1002 1023
1003 bool operator ==(Object other) { 1024 bool operator ==(Object other) {
1004 return super == other; 1025 return super == other;
1005 } 1026 }
1027
1028 int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1);
1029 int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2);
1030
1031 // Loads up to 2 code units into a single integer.
1032 int _codeUnitsAt(int index, int count) {
1033 assert(index >= 0);
1034 assert(index + count - 1 < this.length);
1035 assert(0 < count && count <= 2);
1036
1037 int codeUnits = 0;
1038 for (int i = 0; i < count; i++) {
1039 codeUnits |= this.codeUnitAt(index + i) << (i * 16);
1040 }
1041
1042 return codeUnits;
1043 }
1006 } 1044 }
1007 1045
1008 1046
1009 class _ExternalOneByteString extends _StringBase implements String { 1047 class _ExternalOneByteString extends _StringBase implements String {
1010 factory _ExternalOneByteString._uninstantiable() { 1048 factory _ExternalOneByteString._uninstantiable() {
1011 throw new UnsupportedError( 1049 throw new UnsupportedError(
1012 "_ExternalOneByteString can only be allocated by the VM"); 1050 "_ExternalOneByteString can only be allocated by the VM");
1013 } 1051 }
1014 1052
1015 bool _isWhitespace(int codeUnit) { 1053 bool _isWhitespace(int codeUnit) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 class _CodeUnits extends Object with ListMixin<int>, 1113 class _CodeUnits extends Object with ListMixin<int>,
1076 UnmodifiableListMixin<int> { 1114 UnmodifiableListMixin<int> {
1077 /** The string that this is the code units of. */ 1115 /** The string that this is the code units of. */
1078 String _string; 1116 String _string;
1079 1117
1080 _CodeUnits(this._string); 1118 _CodeUnits(this._string);
1081 1119
1082 int get length => _string.length; 1120 int get length => _string.length;
1083 int operator[](int i) => _string.codeUnitAt(i); 1121 int operator[](int i) => _string.codeUnitAt(i);
1084 } 1122 }
OLDNEW
« no previous file with comments | « runtime/lib/regexp_patch.dart ('k') | runtime/vm/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698