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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_helper.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 | « sdk/lib/_internal/compiler/js_lib/core_patch.dart ('k') | tests/corelib/string_fromcharcodes_test.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/js_helper.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
index 313d2cb43c257ae90db0aa31a2a5eb0597f33a01..4cce9fd08b3259ce6a3717ab69e7bb19face72a9 100644
--- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart
+++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart
@@ -60,6 +60,8 @@ import 'dart:_interceptors';
import 'dart:_internal' as _symbol_dev;
import 'dart:_internal' show MappedIterable;
+import 'dart:_native_typed_data';
+
import 'dart:_js_names' show
extractKeys,
mangledNames,
@@ -764,19 +766,17 @@ class Primitives {
// This is to avoid stack overflows due to very large argument arrays in
// apply(). It fixes http://dartbug.com/6919
static String _fromCharCodeApply(List<int> array) {
- String result = "";
const kMaxApply = 500;
int end = array.length;
- for (var i = 0; i < end; i += kMaxApply) {
- var subarray;
- if (end <= kMaxApply) {
- subarray = array;
- } else {
- subarray = JS('JSExtendableArray', r'#.slice(#, #)', array,
- i, i + kMaxApply < end ? i + kMaxApply : end);
- }
- result = JS('String', '# + String.fromCharCode.apply(#, #)',
- result, null, subarray);
+ if (end <= kMaxApply) {
+ return JS('String', r'String.fromCharCode.apply(null, #)', array);
+ }
+ String result = '';
+ for (int i = 0; i < end; i += kMaxApply) {
+ int chunkEnd = (i + kMaxApply < end) ? i + kMaxApply : end;
+ result = JS('String',
+ r'# + String.fromCharCode.apply(null, #.slice(#, #))',
+ result, array, i, chunkEnd);
}
return result;
}
@@ -806,6 +806,24 @@ class Primitives {
return _fromCharCodeApply(charCodes);
}
+ // [start] and [end] are validated.
+ static String stringFromNativeUint8List(
+ NativeUint8List charCodes, int start, int end) {
+ const kMaxApply = 500;
+ if (end <= kMaxApply && start == 0 && end == charCodes.length) {
+ return JS('String', r'String.fromCharCode.apply(null, #)', charCodes);
+ }
+ String result = '';
+ for (int i = start; i < end; i += kMaxApply) {
+ int chunkEnd = (i + kMaxApply < end) ? i + kMaxApply : end;
+ result = JS('String',
+ r'# + String.fromCharCode.apply(null, #.subarray(#, #))',
+ result, charCodes, i, chunkEnd);
+ }
+ return result;
+ }
+
+
static String stringFromCharCode(charCode) {
if (0 <= charCode) {
if (charCode <= 0xffff) {
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/core_patch.dart ('k') | tests/corelib/string_fromcharcodes_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698