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

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

Issue 51333005: Add Uint32x4List to typed_data (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | « runtime/vm/symbols.h ('k') | sdk/lib/typed_data/typed_data.dart » ('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 4b7ea7b8004adee6498c6b2f321dd49e3ce49db2..f8a1c6131fc516bc109b1e280acf225a050268c1 100644
--- a/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart
+++ b/sdk/lib/typed_data/dart2js/typed_data_dart2js.dart
@@ -83,7 +83,7 @@ class TypedData native "ArrayBufferView" {
int _checkSublistArguments(int start, int end, int length) {
// For `sublist` the [start] and [end] indices are allowed to be equal to
- // [length]. However, [_checkIndex] only allows incides in the range
+ // [length]. However, [_checkIndex] only allows indices in the range
// 0 .. length - 1. We therefore increment the [length] argument by one
// for the [_checkIndex] checks.
_checkIndex(start, length + 1);
@@ -728,7 +728,7 @@ class Float32x4List
int _checkSublistArguments(int start, int end, int length) {
// For `sublist` the [start] and [end] indices are allowed to be equal to
- // [length]. However, [_checkIndex] only allows incides in the range
+ // [length]. However, [_checkIndex] only allows indices in the range
// 0 .. length - 1. We therefore increment the [length] argument by one
// for the [_checkIndex] checks.
_checkIndex(start, length + 1);
@@ -795,6 +795,103 @@ class Float32x4List
}
+class Uint32x4List
+ extends Object with ListMixin<Uint32x4>, FixedLengthListMixin<Uint32x4>
+ implements List<Uint32x4>, TypedData {
+
+ final Uint32List _storage;
+
+ ByteBuffer get buffer => _storage.buffer;
+
+ int get lengthInBytes => _storage.lengthInBytes;
+
+ int get offsetInBytes => _storage.offsetInBytes;
+
+ final int elementSizeInBytes = 16;
+
+ void _invalidIndex(int index, int length) {
+ if (index < 0 || index >= length) {
+ throw new RangeError.range(index, 0, length);
+ } else {
+ throw new ArgumentError('Invalid list index $index');
+ }
+ }
+
+ void _checkIndex(int index, int length) {
+ if (JS('bool', '(# >>> 0 != #)', index, index) || index >= length) {
+ _invalidIndex(index, length);
+ }
+ }
+
+ int _checkSublistArguments(int start, int end, int length) {
+ // For `sublist` the [start] and [end] indices are allowed to be equal to
+ // [length]. However, [_checkIndex] only allows indices in the range
+ // 0 .. length - 1. We therefore increment the [length] argument by one
+ // for the [_checkIndex] checks.
+ _checkIndex(start, length + 1);
+ if (end == null) return length;
+ _checkIndex(end, length + 1);
+ if (start > end) throw new RangeError.range(start, 0, end);
+ return end;
+ }
+
+ Uint32x4List(int length) : _storage = new Uint32List(length*4);
+
+ Uint32x4List._externalStorage(Uint32List storage) : _storage = storage;
+
+ Uint32x4List._slowFromList(List<Uint32x4> list)
+ : _storage = new Uint32List(list.length * 4) {
+ for (int i = 0; i < list.length; i++) {
+ var e = list[i];
+ _storage[(i*4)+0] = e.x;
+ _storage[(i*4)+1] = e.y;
+ _storage[(i*4)+2] = e.z;
+ _storage[(i*4)+3] = e.w;
+ }
+ }
+
+ factory Uint32x4List.fromList(List<Uint32x4> list) {
+ if (list is Uint32x4List) {
+ Uint32x4List nativeList = list as Uint32x4List;
+ return new Uint32x4List._externalStorage(
+ new Uint32List.fromList(nativeList._storage));
+ } else {
+ return new Uint32x4List._slowFromList(list);
+ }
+ }
+
+ Uint32x4List.view(ByteBuffer buffer,
+ [int byteOffset = 0, int length])
+ : _storage = new Uint32List.view(buffer, byteOffset, length);
+
+ static const int BYTES_PER_ELEMENT = 16;
+
+ int get length => _storage.length ~/ 4;
+
+ Uint32x4 operator[](int index) {
+ _checkIndex(index, length);
+ double _x = _storage[(index*4)+0];
+ double _y = _storage[(index*4)+1];
+ double _z = _storage[(index*4)+2];
+ double _w = _storage[(index*4)+3];
+ return new Uint32x4(_x, _y, _z, _w);
+ }
+
+ void operator[]=(int index, Uint32x4 value) {
+ _checkIndex(index, length);
+ _storage[(index*4)+0] = value._storage[0];
+ _storage[(index*4)+1] = value._storage[1];
+ _storage[(index*4)+2] = value._storage[2];
+ _storage[(index*4)+3] = value._storage[3];
+ }
+
+ List<Uint32x4> sublist(int start, [int end]) {
+ end = _checkSublistArguments(start, end, length);
+ return new Uint32x4List._externalStorage(_storage.sublist(start*4, end*4));
+ }
+}
+
+
class Float32x4 {
final _storage = new Float32List(4);
« no previous file with comments | « runtime/vm/symbols.h ('k') | sdk/lib/typed_data/typed_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698