Chromium Code Reviews| Index: runtime/lib/string_patch.dart |
| =================================================================== |
| --- runtime/lib/string_patch.dart (revision 29294) |
| +++ runtime/lib/string_patch.dart (working copy) |
| @@ -84,12 +84,12 @@ |
| if (identical(this, other)) { |
| return true; |
| } |
| - if ((other is !String) || |
| + // TODO(5413632): Compare hash codes when both are present. |
|
Ivan Posva
2013/10/28 23:35:09
I don't think comparing hash codes is effective, a
srdjan
2013/10/29 17:02:29
Done.
|
| + if ((other is! String) || |
| (this.length != other.length)) { |
| - // TODO(5413632): Compare hash codes when both are present. |
| return false; |
| } |
| - final len = this.length; |
| + final int len = this.length; |
|
Ivan Posva
2013/10/28 23:35:09
?
srdjan
2013/10/29 17:02:29
Removed type.
|
| for (int i = 0; i < len; i++) { |
| if (this.codeUnitAt(i) != other.codeUnitAt(i)) { |
| return false; |
| @@ -424,7 +424,7 @@ |
| if (isOneByteString) { |
| return _OneByteString._concatAll(stringList, totalLength); |
| } |
| - return _concatAllNative(stringList, 0, stringList.length); |
| + return _concatRangeNative(stringList, 0, stringList.length); |
| } |
| Iterable<Match> allMatches(String str) { |
| @@ -509,10 +509,31 @@ |
| String toLowerCase() native "String_toLowerCase"; |
| + // Concatenate ['start', 'end'[ elements of 'strings'. 'strings' must contain |
| + // String elements. Optimized for OneByteStrings. |
| + static String _concatRange(List<String> strings, int start, int end) { |
| + if ((end - start) == 1) { |
| + return strings[start]; |
| + } |
| + final int numValues = strings.length; |
| + if (start == 0 && (end == numValues)) { |
|
Ivan Posva
2013/10/28 23:35:09
(start == 0)
srdjan
2013/10/29 17:02:29
Done.
|
| + int totalLength = 0; |
| + for (int i = 0; i < numValues; i++) { |
| + String s = strings[i]; |
| + if (s._cid != _OneByteString._classId) { |
| + return _concatRangeNative(strings, start, end); |
| + } |
| + totalLength += s.length; |
| + } |
| + return _OneByteString._concatAll(strings, totalLength); |
| + } |
| + return _concatRangeNative(strings, start, end); |
| + } |
| + |
| // Call this method if not all list elements are known to be OneByteString(s). |
| // 'strings' must be an _List or _GrowableList. |
| - static String _concatAllNative(List<String> strings, int start, int end) |
| - native "Strings_concatAll"; |
| + static String _concatRangeNative(List<String> strings, int start, int end) |
| + native "String_concatRange"; |
| } |
| @@ -548,11 +569,11 @@ |
| } |
| // All element of 'strings' must be OneByteStrings. |
| - static _concatAll(_List<String> strings, int totalLength) { |
| + static _concatAll(List<String> strings, int totalLength) { |
| // TODO(srdjan): Improve code below and raise or eliminate the limit. |
| if (totalLength > 128) { |
| // Native is quicker. |
| - return _StringBase._concatAllNative(strings, 0, strings.length); |
| + return _StringBase._concatRangeNative(strings, 0, strings.length); |
| } |
| var res = _OneByteString._allocate(totalLength); |
| final stringsLength = strings.length; |
| @@ -567,6 +588,23 @@ |
| return res; |
| } |
| + int indexOf(Pattern pattern, [int start = 0]) { |
| + final int len = this.length; |
|
Ivan Posva
2013/10/28 23:35:09
Not sure whether we should be using this. or not.
srdjan
2013/10/29 17:02:29
The name' length' is too generic, therefore I feel
|
| + // Specialize for single character pattern. |
| + if ((pattern._cid == _OneByteString._classId) && |
|
Ivan Posva
2013/10/28 23:35:09
What about an ExternalOneByteString?
srdjan
2013/10/29 17:02:29
Added: TODO. The inner loop should stay monomorphi
|
| + (pattern.length == 1) && |
| + (start >= 0) && (start < len)) { |
| + final int patternCu0 = pattern.codeUnitAt(0); |
|
Ivan Posva
2013/10/28 23:35:09
Another quick test you could do: If the pattern is
srdjan
2013/10/29 17:02:29
Good idea, once I allow two byte strings.
|
| + for (int i = start; i < len; i++) { |
| + if (this.codeUnitAt(i) == patternCu0) { |
| + return i; |
| + } |
| + } |
| + return -1; |
| + } |
| + return super.indexOf(pattern, start); |
| + } |
| + |
| // Allocates a string of given length, expecting its content to be |
| // set using _setAt. |
| static _OneByteString _allocate(int length) native "OneByteString_allocate"; |