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

Unified Diff: runtime/lib/byte_array.dart

Issue 11694009: Move common logic into the base class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/byte_array.dart
diff --git a/runtime/lib/byte_array.dart b/runtime/lib/byte_array.dart
index 61be89d704c817b3444a63fd50dfd7b2bddab733..b7a77af9ce2e1e805854260e9e1c03217fa9a670 100644
--- a/runtime/lib/byte_array.dart
+++ b/runtime/lib/byte_array.dart
@@ -1808,6 +1808,12 @@ class _ByteArrayView implements ByteArray {
class _ByteArrayViewBase {
+ final ByteArray _array;
cshapiro 2013/01/07 23:25:58 Can you move the private field declarations to the
Anton Muhin 2013/01/09 15:35:57 Done.
+ final int _offset;
+ final int length;
+
+ _ByteArrayViewBase(this._array, this._offset, this.length);
+
num operator[](int index);
// Methods implementing the Collection interface.
@@ -1844,8 +1850,6 @@ class _ByteArrayViewBase {
return this.length == 0;
}
- int get length;
-
// Methods implementing the List interface.
set length(newLength) {
@@ -1913,30 +1917,25 @@ class _ByteArrayViewBase {
class _Int8ArrayView extends _ByteArrayViewBase implements Int8List {
- _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Int8ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getInt8(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setInt8(_offset + (index * _BYTES_PER_ELEMENT), _toInt8(value));
@@ -1966,7 +1965,7 @@ class _Int8ArrayView extends _ByteArrayViewBase implements Int8List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -1978,37 +1977,29 @@ class _Int8ArrayView extends _ByteArrayViewBase implements Int8List {
}
static const int _BYTES_PER_ELEMENT = 1;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List {
- _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Uint8ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getUint8(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setUint8(_offset + (index * _BYTES_PER_ELEMENT), _toUint8(value));
@@ -2038,7 +2029,7 @@ class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2050,37 +2041,29 @@ class _Uint8ArrayView extends _ByteArrayViewBase implements Uint8List {
}
static const int _BYTES_PER_ELEMENT = 1;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Int16ArrayView extends _ByteArrayViewBase implements Int16List {
- _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Int16ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getInt16(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setInt16(_offset + (index * _BYTES_PER_ELEMENT), _toInt16(value));
@@ -2110,7 +2093,7 @@ class _Int16ArrayView extends _ByteArrayViewBase implements Int16List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2122,37 +2105,29 @@ class _Int16ArrayView extends _ByteArrayViewBase implements Int16List {
}
static const int _BYTES_PER_ELEMENT = 2;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List {
- _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Uint16ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getUint16(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setUint16(_offset + (index * _BYTES_PER_ELEMENT), _toUint16(value));
@@ -2182,7 +2157,7 @@ class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2194,37 +2169,29 @@ class _Uint16ArrayView extends _ByteArrayViewBase implements Uint16List {
}
static const int _BYTES_PER_ELEMENT = 2;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Int32ArrayView extends _ByteArrayViewBase implements Int32List {
- _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Int32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getInt32(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setInt32(_offset + (index * _BYTES_PER_ELEMENT), _toInt32(value));
@@ -2254,7 +2221,7 @@ class _Int32ArrayView extends _ByteArrayViewBase implements Int32List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2266,37 +2233,29 @@ class _Int32ArrayView extends _ByteArrayViewBase implements Int32List {
}
static const int _BYTES_PER_ELEMENT = 4;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List {
- _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Uint32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getUint32(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setUint32(_offset + (index * _BYTES_PER_ELEMENT), _toUint32(value));
@@ -2326,7 +2285,7 @@ class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2338,37 +2297,29 @@ class _Uint32ArrayView extends _ByteArrayViewBase implements Uint32List {
}
static const int _BYTES_PER_ELEMENT = 4;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Int64ArrayView extends _ByteArrayViewBase implements Int64List {
- _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Int64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getInt64(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setInt64(_offset + (index * _BYTES_PER_ELEMENT), _toInt64(value));
@@ -2398,7 +2349,7 @@ class _Int64ArrayView extends _ByteArrayViewBase implements Int64List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2410,37 +2361,29 @@ class _Int64ArrayView extends _ByteArrayViewBase implements Int64List {
}
static const int _BYTES_PER_ELEMENT = 8;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List {
- _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Uint64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
int operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getUint64(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, int value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setUint64(_offset + (index * _BYTES_PER_ELEMENT), _toUint64(value));
@@ -2470,7 +2413,7 @@ class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2482,37 +2425,29 @@ class _Uint64ArrayView extends _ByteArrayViewBase implements Uint64List {
}
static const int _BYTES_PER_ELEMENT = 8;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Float32ArrayView extends _ByteArrayViewBase implements Float32List {
- _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Float32ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
double operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getFloat32(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, double value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setFloat32(_offset + (index * _BYTES_PER_ELEMENT), value);
@@ -2542,7 +2477,7 @@ class _Float32ArrayView extends _ByteArrayViewBase implements Float32List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2554,37 +2489,29 @@ class _Float32ArrayView extends _ByteArrayViewBase implements Float32List {
}
static const int _BYTES_PER_ELEMENT = 4;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
class _Float64ArrayView extends _ByteArrayViewBase implements Float64List {
- _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int length])
- : _array = array,
- _offset = _requireInteger(offsetInBytes),
- _length = _requireIntegerOrNull(
- length,
- ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT)) {
- _rangeCheck(array.lengthInBytes(), _offset, _length * _BYTES_PER_ELEMENT);
- }
-
- get length {
- return _length;
+ _Float64ArrayView(ByteArray array, [int offsetInBytes = 0, int _length])
+ : super(array, _requireInteger(offsetInBytes),
+ _requireIntegerOrNull(
+ _length,
+ ((array.lengthInBytes() - offsetInBytes) ~/ _BYTES_PER_ELEMENT))) {
+ _rangeCheck(array.lengthInBytes(), _offset, length * _BYTES_PER_ELEMENT);
}
double operator[](int index) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
return _array.getFloat64(_offset + (index * _BYTES_PER_ELEMENT));
}
void operator[]=(int index, double value) {
- if (index < 0 || index >= _length) {
- String message = "$index must be in the range [0..$_length)";
+ if (index < 0 || index >= length) {
+ String message = "$index must be in the range [0..$length)";
throw new RangeError(message);
}
_array.setFloat64(_offset + (index * _BYTES_PER_ELEMENT), value);
@@ -2614,7 +2541,7 @@ class _Float64ArrayView extends _ByteArrayViewBase implements Float64List {
}
int lengthInBytes() {
- return _length * _BYTES_PER_ELEMENT;
+ return length * _BYTES_PER_ELEMENT;
}
ByteArray asByteArray([int start = 0, int length]) {
@@ -2626,7 +2553,4 @@ class _Float64ArrayView extends _ByteArrayViewBase implements Float64List {
}
static const int _BYTES_PER_ELEMENT = 8;
- final ByteArray _array;
- final int _offset;
- final int _length;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698