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

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

Issue 364833002: Add typed data view creation functions on ByteBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 6 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/typed_data/dart2js/typed_data_dart2js.dart ('k') | tests/standalone/typed_data_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/typed_data/typed_data.dart
diff --git a/sdk/lib/typed_data/typed_data.dart b/sdk/lib/typed_data/typed_data.dart
index 66a86bccd08c4ff31e0f32cd5cea3a5f52aed19f..665de4bfff0b5ed05f7487ce6169251e6f37063b 100644
--- a/sdk/lib/typed_data/typed_data.dart
+++ b/sdk/lib/typed_data/typed_data.dart
@@ -17,6 +17,66 @@ abstract class ByteBuffer {
*/
int get lengthInBytes;
+ /**
+ * Creates a new [Uint8List] view of this buffer.
+ */
+ Uint8List asUint8List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Int8List] view of this buffer.
+ */
+ Int8List asInt8List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Uint8Clamped] view of this buffer.
+ */
+ Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Uint16List] view of this buffer.
+ */
+ Uint16List asUint16List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Int16List] view of this buffer.
+ */
+ Int16List asInt16List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Uint32List] view of this buffer.
+ */
+ Uint32List asUint32List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Int32List] view of this buffer.
+ */
+ Int32List asInt32List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Uint64List] view of this buffer.
+ */
+ Uint64List asUint64List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Int64List] view of this buffer.
+ */
+ Int64List asInt64List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Int32x4List] view of this buffer.
+ */
+ Int32x4List asInt32x4List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Float32List] view of this buffer.
+ */
+ Float32List asFloat32List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Float64List] view of this buffer.
+ */
+ Float64List asFloat64List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Float32x4List] view of this buffer.
+ */
+ Float32x4List asFloat32x4List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [Float64x2List] view of this buffer.
+ */
+ Float64x2List asFloat64x2List([int offsetInBytes = 0, int length]);
+ /**
+ * Creates a new [ByteData] view of this buffer.
+ */
+ ByteData asByteData([int offsetInBytes = 0, int length]);
}
@@ -102,8 +162,10 @@ abstract class ByteData implements TypedData {
* if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
* the length of [buffer].
*/
- external factory ByteData.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory ByteData.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asByteData(offsetInBytes, length);
+ }
/**
* Returns the (possibly negative) integer represented by the byte at the
@@ -381,8 +443,10 @@ abstract class Int8List implements List<int>, TypedData {
* if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
* the length of [buffer].
*/
- external factory Int8List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Int8List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asInt8List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 1;
}
@@ -418,8 +482,10 @@ abstract class Uint8List implements List<int>, TypedData {
* if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
* the length of [buffer].
*/
- external factory Uint8List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Uint8List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asUint8List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 1;
}
@@ -456,8 +522,10 @@ abstract class Uint8ClampedList implements List<int>, TypedData {
* if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
* the length of [buffer].
*/
- external factory Uint8ClampedList.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Uint8ClampedList.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asUint8ClampedList(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 1;
}
@@ -496,8 +564,10 @@ abstract class Int16List implements List<int>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Int16List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Int16List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asInt16List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 2;
}
@@ -536,8 +606,10 @@ abstract class Uint16List implements List<int>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Uint16List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Uint16List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asUint16List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 2;
}
@@ -576,8 +648,10 @@ abstract class Int32List implements List<int>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Int32List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Int32List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asInt32List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 4;
}
@@ -616,8 +690,10 @@ abstract class Uint32List implements List<int>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Uint32List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Uint32List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asUint32List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 4;
}
@@ -656,8 +732,10 @@ abstract class Int64List implements List<int>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Int64List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Int64List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asInt64List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 8;
}
@@ -697,8 +775,10 @@ abstract class Uint64List implements List<int>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Uint64List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Uint64List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asUint64List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 8;
}
@@ -738,8 +818,10 @@ abstract class Float32List implements List<double>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Float32List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Float32List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asFloat32List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 4;
}
@@ -779,8 +861,10 @@ abstract class Float64List implements List<double>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Float64List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Float64List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asFloat64List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 8;
}
@@ -819,8 +903,10 @@ abstract class Float32x4List implements List<Float32x4>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Float32x4List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Float32x4List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asFloat32x4List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 16;
}
@@ -859,8 +945,10 @@ abstract class Int32x4List implements List<Int32x4>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Int32x4List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Int32x4List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asInt32x4List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 16;
}
@@ -899,8 +987,10 @@ abstract class Float64x2List implements List<Float64x2>, TypedData {
* Throws [ArgumentError] if [offsetInBytes] is not a multiple of
* [BYTES_PER_ELEMENT].
*/
- external factory Float64x2List.view(ByteBuffer buffer,
- [int offsetInBytes = 0, int length]);
+ factory Float64x2List.view(ByteBuffer buffer,
+ [int offsetInBytes = 0, int length]) {
+ return buffer.asFloat64x2List(offsetInBytes, length);
+ }
static const int BYTES_PER_ELEMENT = 16;
}
« no previous file with comments | « sdk/lib/typed_data/dart2js/typed_data_dart2js.dart ('k') | tests/standalone/typed_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698