Chromium Code Reviews| Index: runtime/lib/string_patch.dart |
| diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart |
| index 9d5111bd9ea391f0a5d643bbfcdd81440fb9057b..fb06a522478adfebc2e8c9d695987b20aa57f8de 100644 |
| --- a/runtime/lib/string_patch.dart |
| +++ b/runtime/lib/string_patch.dart |
| @@ -34,31 +34,40 @@ class _StringBase { |
| */ |
| static String createFromCharCodes(Iterable<int> charCodes) { |
| if (charCodes != null) { |
| - // TODO(srdjan): Also skip copying of typed arrays. |
| + // TODO(srdjan): Also skip copying of wide typed arrays. |
| final ccid = charCodes._cid; |
| + bool isOneByteString = false; |
| if ((ccid != _List._classId) && |
| (ccid != _GrowableList._classId) && |
| (ccid != _ImmutableList._classId)) { |
| - charCodes = new List<int>.from(charCodes, growable: false); |
| - } |
| - |
| - bool isOneByteString = true; |
| - for (int i = 0; i < charCodes.length; i++) { |
| - int e = charCodes[i]; |
| - if (e is! _Smi) throw new ArgumentError(e); |
| - // Is e Latin1? |
| - if ((e < 0) || (e > 0xFF)) { |
| - isOneByteString = false; |
| - break; |
| + if (charCodes is Uint8List || charCodes is Int8List) { |
|
srdjan
2013/11/20 16:06:57
Add parentheses around is tests.
Anders Johnsen
2013/11/21 06:06:27
Done.
|
| + isOneByteString = true; |
| + } else { |
| + charCodes = new List<int>.from(charCodes, growable: false); |
| } |
| } |
| - if (isOneByteString) { |
| - var s = _OneByteString._allocate(charCodes.length); |
| + |
| + if (!isOneByteString) { |
| for (int i = 0; i < charCodes.length; i++) { |
|
srdjan
2013/11/20 16:06:57
You may want to prefetch chatCodes.length and keep
Anders Johnsen
2013/11/21 06:06:27
Done.
|
| - s._setAt(i, charCodes[i]); |
| + int e = charCodes[i]; |
| + if (e is! _Smi) throw new ArgumentError(e); |
| + // Is e Latin1? |
| + if ((e < 0) || (e > 0xFF)) { |
| + return _createFromCodePoints(charCodes); |
| + } |
| } |
| - return s; |
| } |
| + |
| + // Allocate a one byte string. |
|
srdjan
2013/11/20 16:06:57
Add a comment that above the threshold, the native
Anders Johnsen
2013/11/21 06:06:27
Just did a test with normal lists. 128 is indeed t
|
| + if (charCodes.length >= 128) { |
| + return _OneByteString._allocateFromOneByteList(charCodes); |
| + } |
| + |
| + var s = _OneByteString._allocate(charCodes.length); |
| + for (int i = 0; i < charCodes.length; i++) { |
| + s._setAt(i, charCodes[i]); |
| + } |
| + return s; |
| } |
| return _createFromCodePoints(charCodes); |
| } |
| @@ -628,6 +637,10 @@ class _OneByteString extends _StringBase implements String { |
| // set using _setAt. |
| static _OneByteString _allocate(int length) native "OneByteString_allocate"; |
| + |
| + static _OneByteString _allocateFromOneByteList(List<int> list) |
| + native "OneByteString_allocateFromOneByteList"; |
| + |
| // This is internal helper method. Code point value must be a valid |
| // Latin1 value (0..0xFF), index must be valid. |
| void _setAt(int index, int codePoint) native "OneByteString_setAt"; |