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

Unified Diff: sdk/lib/typed_data/dart2js/typed_data_dart2js.dart

Issue 104923005: Redo "Use TypedArray.set for setRange of between similarly typed lists implemented as TypedArrays" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 | tests/lib/lib.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/typed_data/dart2js/typed_data_dart2js.dart
diff --git a/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart b/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart
index 6a4e0f1ac7b129a5cf8a71924881e398e5435efc..f91472af77c2c05631253d0e58392fb15280e737 100644
--- a/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart
+++ b/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart
@@ -456,16 +456,78 @@ class ByteData extends TypedData native "DataView" {
JS('ByteData', 'new DataView(#, #, #)', arg1, arg2, arg3);
}
+
+// TODO(sra): Move this type to a public name in a private library so that other
+// platform libraries like dart:html and dart:webaudio can tell a native array
+// from a list that implements the implicit interface.
+abstract class _NativeTypedArray extends TypedData
+ implements JavaScriptIndexingBehavior {
+ int get length => JS("JSUInt32", '#.length', this);
+
+ bool _setRangeFast(int start, int end,
+ _NativeTypedArray source, int skipCount) {
+ int targetLength = this.length;
+ _checkIndex(start, targetLength + 1);
+ _checkIndex(end, targetLength + 1);
+ if (start > end) throw new RangeError.range(start, 0, end);
+ int count = end - start;
+
+ if (skipCount < 0) throw new ArgumentError(skipCount);
+
+ int sourceLength = source.length;
+ if (sourceLength - skipCount < count) {
+ throw new StateError("Not enough elements");
+ }
+
+ if (skipCount != 0 || sourceLength != count) {
+ // Create a view of the exact subrange that is copied from the source.
+ source = JS('', '#.subarray(#, #)',
+ source, skipCount, skipCount + count);
+ }
+ JS('void', '#.set(#, #)', this, source, start);
+ }
+}
+
+// TODO(sra): Move to private library, like [_NativeTypedArray].
+abstract class _NativeTypedArrayOfDouble
+ extends _NativeTypedArray
+ with ListMixin<double>, FixedLengthListMixin<double>
+ implements List<double> {
+
+ void setRange(int start, int end, Iterable<double> iterable,
+ [int skipCount = 0]) {
+ if (iterable is _NativeTypedArrayOfDouble) {
+ _setRangeFast(start, end, iterable, skipCount);
+ return;
+ }
+ super.setRange(start, end, iterable, skipCount);
+ }
+}
+
+// TODO(sra): Move to private library, like [_NativeTypedArray].
+abstract class _NativeTypedArrayOfInt
+ extends _NativeTypedArray
+ with ListMixin<int>, FixedLengthListMixin<int>
+ implements List<int> {
+
+ void setRange(int start, int end, Iterable<int> iterable,
+ [int skipCount = 0]) {
+ if (iterable is _NativeTypedArrayOfInt) {
+ _setRangeFast(start, end, iterable, skipCount);
+ return;
+ }
+ super.setRange(start, end, iterable, skipCount);
+ }
+}
+
+
/**
* A fixed-length list of IEEE 754 single-precision binary floating-point
* numbers that is viewable as a [TypedData]. For long lists, this
* implementation can be considerably more space- and time-efficient than
* the default [List] implementation.
*/
-class Float32List
- extends TypedData with ListMixin<double>, FixedLengthListMixin<double>
- implements JavaScriptIndexingBehavior, List<double>
- native "Float32Array" {
+class Float32List extends _NativeTypedArrayOfDouble native "Float32Array" {
/**
* Creates a [Float32List] of the specified length (in elements), all of
* whose elements are initially zero.
@@ -502,8 +564,6 @@ class Float32List
static const int BYTES_PER_ELEMENT = 4;
- int get length => JS("JSUInt32", '#.length', this);
-
num operator[](int index) {
_checkIndex(index, length);
return JS("num", "#[#]", this, index);
@@ -537,10 +597,7 @@ class Float32List
* implementation can be considerably more space- and time-efficient than
* the default [List] implementation.
*/
-class Float64List
- extends TypedData with ListMixin<double>, FixedLengthListMixin<double>
- implements JavaScriptIndexingBehavior, List<double>
- native "Float64Array" {
+class Float64List extends _NativeTypedArrayOfDouble native "Float64Array" {
/**
* Creates a [Float64List] of the specified length (in elements), all of
* whose elements are initially zero.
@@ -577,8 +634,6 @@ class Float64List
static const int BYTES_PER_ELEMENT = 8;
- int get length => JS("JSUInt32", '#.length', this);
-
num operator[](int index) {
_checkIndex(index, length);
return JS("num", "#[#]", this, index);
@@ -614,10 +669,7 @@ class Float64List
* [TypedData]. For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Int16List
- extends TypedData with ListMixin<int>, FixedLengthListMixin<int>
- implements JavaScriptIndexingBehavior, List<int>
- native "Int16Array" {
+class Int16List extends _NativeTypedArrayOfInt native "Int16Array" {
/**
* Creates an [Int16List] of the specified length (in elements), all of
* whose elements are initially zero.
@@ -653,8 +705,6 @@ class Int16List
static const int BYTES_PER_ELEMENT = 2;
- int get length => JS("JSUInt32", '#.length', this);
-
int operator[](int index) {
_checkIndex(index, length);
return JS("int", "#[#]", this, index);
@@ -687,10 +737,7 @@ class Int16List
* [TypedData]. For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Int32List
- extends TypedData with ListMixin<int>, FixedLengthListMixin<int>
- implements JavaScriptIndexingBehavior, List<int>
- native "Int32Array" {
+class Int32List extends _NativeTypedArrayOfInt native "Int32Array" {
/**
* Creates an [Int32List] of the specified length (in elements), all of
* whose elements are initially zero.
@@ -726,8 +773,6 @@ class Int32List
static const int BYTES_PER_ELEMENT = 4;
- int get length => JS("JSUInt32", '#.length', this);
-
int operator[](int index) {
_checkIndex(index, length);
return JS("int", "#[#]", this, index);
@@ -760,10 +805,7 @@ class Int32List
* For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Int8List
- extends TypedData with ListMixin<int>, FixedLengthListMixin<int>
- implements JavaScriptIndexingBehavior, List<int>
- native "Int8Array" {
+class Int8List extends _NativeTypedArrayOfInt native "Int8Array" {
/**
* Creates an [Int8List] of the specified length (in elements), all of
* whose elements are initially zero.
@@ -796,8 +838,6 @@ class Int8List
static const int BYTES_PER_ELEMENT = 1;
- int get length => JS("JSUInt32", '#.length', this);
-
int operator[](int index) {
_checkIndex(index, length);
return JS("int", "#[#]", this, index);
@@ -830,10 +870,7 @@ class Int8List
* [TypedData]. For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Uint16List
- extends TypedData with ListMixin<int>, FixedLengthListMixin<int>
- implements JavaScriptIndexingBehavior, List<int>
- native "Uint16Array" {
+class Uint16List extends _NativeTypedArrayOfInt native "Uint16Array" {
/**
* Creates a [Uint16List] of the specified length (in elements), all
* of whose elements are initially zero.
@@ -870,8 +907,6 @@ class Uint16List
static const int BYTES_PER_ELEMENT = 2;
- int get length => JS("JSUInt32", '#.length', this);
-
int operator[](int index) {
_checkIndex(index, length);
return JS("JSUInt31", "#[#]", this, index);
@@ -904,10 +939,7 @@ class Uint16List
* [TypedData]. For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Uint32List
- extends TypedData with ListMixin<int>, FixedLengthListMixin<int>
- implements JavaScriptIndexingBehavior, List<int>
- native "Uint32Array" {
+class Uint32List extends _NativeTypedArrayOfInt native "Uint32Array" {
/**
* Creates a [Uint32List] of the specified length (in elements), all
* of whose elements are initially zero.
@@ -944,8 +976,6 @@ class Uint32List
static const int BYTES_PER_ELEMENT = 4;
- int get length => JS("JSUInt32", '#.length', this);
-
int operator[](int index) {
_checkIndex(index, length);
return JS("JSUInt32", "#[#]", this, index);
@@ -979,8 +1009,7 @@ class Uint32List
* more space- and time-efficient than the default [List] implementation.
* Indexed store clamps the value to range 0..0xFF.
*/
-class Uint8ClampedList extends TypedData with ListMixin<int>,
- FixedLengthListMixin<int> implements JavaScriptIndexingBehavior, List<int>
+class Uint8ClampedList extends _NativeTypedArrayOfInt
native "Uint8ClampedArray,CanvasPixelArray" {
/**
* Creates a [Uint8ClampedList] of the specified length (in elements), all of
@@ -1050,9 +1079,7 @@ class Uint8ClampedList extends TypedData with ListMixin<int>,
* For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Uint8List
- extends TypedData with ListMixin<int>, FixedLengthListMixin<int>
- implements JavaScriptIndexingBehavior, List<int>
+class Uint8List extends _NativeTypedArrayOfInt
// On some browsers Uint8ClampedArray is a subtype of Uint8Array. Marking
// Uint8List as !nonleaf ensures that the native dispatch correctly handles
// the potential for Uint8ClampedArray to 'accidentally' pick up the
@@ -1125,7 +1152,9 @@ class Uint8List
* [TypedData]. For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Int64List extends TypedData implements JavaScriptIndexingBehavior, List<int> {
+class Int64List
+ extends TypedData
+ implements JavaScriptIndexingBehavior, List<int> {
/**
* Creates an [Int64List] of the specified length (in elements), all of
* whose elements are initially zero.
@@ -1170,7 +1199,9 @@ class Int64List extends TypedData implements JavaScriptIndexingBehavior, List<in
* [TypedData]. For long lists, this implementation can be considerably
* more space- and time-efficient than the default [List] implementation.
*/
-class Uint64List extends TypedData implements JavaScriptIndexingBehavior, List<int> {
+class Uint64List
+ extends TypedData
+ implements JavaScriptIndexingBehavior, List<int> {
/**
* Creates a [Uint64List] of the specified length (in elements), all
* of whose elements are initially zero.
« no previous file with comments | « no previous file | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698