Chromium Code Reviews| 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..6752d1dbfcda4cbda11016e4badf83f9605ee6ca 100644 |
| --- a/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart |
| +++ b/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart |
| @@ -456,16 +456,75 @@ class ByteData extends TypedData native "DataView" { |
| JS('ByteData', 'new DataView(#, #, #)', arg1, arg2, arg3); |
| } |
| + |
| +// TODO(sra): Hide this type. |
|
Cutch
2013/12/04 17:50:02
Why not just _NativeTypedArray, _NativeTypedArrayO
sra1
2013/12/04 20:52:50
I will do that for now, but ultimately other libra
|
| +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): Hide this type. |
| +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): Hide this type. |
| +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 +561,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 +594,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 +631,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 +666,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 +702,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 +734,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 +770,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 +802,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 +835,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 +867,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 +904,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 +936,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 +973,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 +1006,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 +1076,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 +1149,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 +1196,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. |