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

Unified Diff: sdk/lib/_internal/compiler/js_lib/core_patch.dart

Issue 860273002: Recognize and special case String.fromCharCodes for Uint8List in JavaScript. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/js_lib/js_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/core_patch.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/core_patch.dart b/sdk/lib/_internal/compiler/js_lib/core_patch.dart
index 29ee7787287406b79905d8f436547aa66d6ec302..3fe172b646c748ea6c5f2a2bfc0ff4fefa7fd81a 100644
--- a/sdk/lib/_internal/compiler/js_lib/core_patch.dart
+++ b/sdk/lib/_internal/compiler/js_lib/core_patch.dart
@@ -14,6 +14,8 @@ import 'dart:_js_helper' show patch,
stringJoinUnchecked,
objectHashCode;
+import 'dart:_native_typed_data' show NativeUint8List;
+
String _symbolToString(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
_symbolMapToStringMap(Map<Symbol, dynamic> map) {
@@ -275,26 +277,14 @@ class String {
@patch
factory String.fromCharCodes(Iterable<int> charCodes,
[int start = 0, int end]) {
- // If possible, recognize typed lists too.
- if (charCodes is! JSArray) {
- return _stringFromIterable(charCodes, start, end);
- }
- List list = charCodes;
- int len = list.length;
- if (start < 0 || start > len) {
- throw new RangeError.range(start, 0, len);
+ if (charCodes is JSArray) {
+ return _stringFromJSArray(charCodes, start, end);
}
- if (end == null) {
- end = len;
- } else if (end < start || end > len) {
- throw new RangeError.range(end, start, len);
+ if (charCodes is NativeUint8List) {
+ return _stringFromUint8List(charCodes, start, end);
}
-
- if (start > 0 || end < len) {
- list = list.sublist(start, end);
- }
- return Primitives.stringFromCharCodes(list);
+ return _stringFromIterable(charCodes, start, end);
}
@patch
@@ -308,6 +298,34 @@ class String {
'String.fromEnvironment can only be used as a const constructor');
}
+ static String _stringFromJSArray(List list, int start, int endOrNull) {
+ int len = list.length;
+ int end = _checkBounds(len, start, endOrNull);
+ if (start > 0 || end < len) {
+ list = list.sublist(start, end);
+ }
+ return Primitives.stringFromCharCodes(list);
+ }
+
+ static String _stringFromUint8List(
+ NativeUint8List charCodes, int start, int endOrNull) {
+ int len = charCodes.length;
+ int end = _checkBounds(len, start, endOrNull);
+ return Primitives.stringFromNativeUint8List(charCodes, start, end);
+ }
+
+ static int _checkBounds(int len, int start, int end) {
+ if (start < 0 || start > len) {
+ throw new RangeError.range(start, 0, len);
+ }
+ if (end == null) {
+ end = len;
+ } else if (end < start || end > len) {
+ throw new RangeError.range(end, start, len);
+ }
+ return end;
+ }
+
static String _stringFromIterable(Iterable<int> charCodes,
int start, int end) {
if (start < 0) throw new RangeError.range(start, 0, charCodes.length);
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/js_lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698