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

Unified Diff: runtime/lib/string_patch.dart

Issue 14862006: Improve performance of String.fromCharCodes by implementing it in Dart. Add tow internal natives to… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/string_patch.dart
===================================================================
--- runtime/lib/string_patch.dart (revision 22374)
+++ runtime/lib/string_patch.dart (working copy)
@@ -27,13 +27,32 @@
* [codePoints].
*/
static String createFromCharCodes(Iterable<int> charCodes) {
- // TODO(srdjan): Also skip copying of typed arrays.
- if (charCodes is! _ObjectArray &&
- charCodes is! _GrowableObjectArray &&
- charCodes is! _ImmutableArray) {
- charCodes = new List<int>.from(charCodes, growable: false);
+ if (charCodes != null) {
+ // TODO(srdjan): Also skip copying of typed arrays.
+ if (charCodes is! _ObjectArray &&
+ charCodes is! _GrowableObjectArray &&
+ charCodes is! _ImmutableArray) {
+ 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! int) throw new ArgumentError(e);
+ // Is e Latin1?
+ if ((e < 0) || (e > 0xFF)) {
+ isOneByteString = false;
+ break;
+ }
+ }
+ if (isOneByteString) {
+ var s = _OneByteString._allocate(charCodes.length);
+ for (int i = 0; i < charCodes.length; i++) {
+ s._setAt(i, charCodes[i]);
+ }
+ return s;
+ }
}
-
return _createFromCodePoints(charCodes);
}
@@ -466,6 +485,13 @@
}
return super.split(pattern);
}
+
+ // Allocates a string of given length, expecting its content to be
+ // set using _setAt.
+ static _OneByteString _allocate(int length) native "OneByteString_allocate";
+
+ // Code point value must be a valid Latin1 (0..0xFF). Index must be valid.
+ void _setAt(int index, int codePoint) native "OneByteString_setAt";
}

Powered by Google App Engine
This is Rietveld 408576698