Chromium Code Reviews| Index: runtime/lib/typed_data.dart |
| diff --git a/runtime/lib/typed_data.dart b/runtime/lib/typed_data.dart |
| index 4fb7fff75d6ad5729379b596a1e02923d638e467..c1aaa041da3ed6539fffc56d98230b1011769e62 100644 |
| --- a/runtime/lib/typed_data.dart |
| +++ b/runtime/lib/typed_data.dart |
| @@ -486,67 +486,59 @@ abstract class _TypedListBase { |
| } |
| void setRange(int start, int end, Iterable from, [int skipCount = 0]) { |
| - // Check ranges. |
| - if ((start < 0) || (start > length)) { |
| - throw _newRangeError(start, length + 1); |
| - } |
| - if ((end < 0) || (end > length)) { |
| - throw _newRangeError(end, length + 1); |
| - } |
| - if (start > end) { |
| - throw _newRangeError(start, end + 1); |
| - } |
| - if (skipCount < 0) { |
|
Ivan Posva
2015/05/14 18:13:18
This part is missed in the new code.
Lasse Reichstein Nielsen
2015/05/18 12:21:09
Acknowledged.
|
| - throw new ArgumentError(skipCount); |
| - } |
| - |
| - final count = end - start; |
| - if ((from.length - skipCount) < count) { |
|
Ivan Posva
2015/05/14 18:13:18
This part will be missed if count is 0 in the new
|
| - throw IterableElementError.tooFew(); |
| - } |
| + if (0 <= start && start <= end && end <= length) { |
|
Ivan Posva
2015/05/14 18:13:18
() around comparisons is generally the style we ar
|
| + final count = end - start; |
| + if (count == 0) return; |
| - if (from is _TypedListBase) { |
| - if (this.elementSizeInBytes == from.elementSizeInBytes) { |
| - if ((count < 10) && (from.buffer != this.buffer)) { |
| - Lists.copy(from, skipCount, this, start, count); |
| - return; |
| - } else if (this.buffer._data._setRange( |
| - start * elementSizeInBytes + this.offsetInBytes, |
| - count * elementSizeInBytes, |
| - from.buffer._data, |
| - skipCount * elementSizeInBytes + from.offsetInBytes, |
| - ClassID.getID(this), ClassID.getID(from))) { |
| - return; |
| - } |
| - } else if (from.buffer == this.buffer) { |
| - // Different element sizes, but same buffer means that we need |
| - // an intermediate structure. |
| - // TODO(srdjan): Optimize to skip copying if the range does not overlap. |
| - final temp_buffer = new List(count); |
| - for (var i = 0; i < count; i++) { |
| - temp_buffer[i] = from[skipCount + i]; |
| + if (from is _TypedListBase) { |
| + if ((from.length - skipCount) < count) { |
| + throw IterableElementError.tooFew(); |
| } |
| - for (var i = start; i < end; i++) { |
| - this[i] = temp_buffer[i - start]; |
| + if (this.elementSizeInBytes == from.elementSizeInBytes) { |
| + if ((count < 10) && (from.buffer != this.buffer)) { |
| + Lists.copy(from, skipCount, this, start, count); |
| + return; |
| + } else if (this.buffer._data._setRange( |
| + start * elementSizeInBytes + this.offsetInBytes, |
| + count * elementSizeInBytes, |
| + from.buffer._data, |
| + skipCount * elementSizeInBytes + from.offsetInBytes, |
| + ClassID.getID(this), ClassID.getID(from))) { |
| + return; |
| + } |
| + } else if (from.buffer == this.buffer) { |
| + // Different element sizes, but same buffer means that we need |
| + // an intermediate structure. |
| + // TODO(srdjan): Optimize to skip copying if the range does not overlap. |
|
Søren Gjesse
2015/05/13 11:22:08
Long line.
Lasse Reichstein Nielsen
2015/05/18 12:21:09
Done.
|
| + final temp_buffer = new List(count); |
| + for (var i = 0; i < count; i++) { |
| + temp_buffer[i] = from[skipCount + i]; |
| + } |
| + for (var i = start; i < end; i++) { |
| + this[i] = temp_buffer[i - start]; |
| + } |
| + return; |
| } |
| - return; |
| } |
| - } |
| - if (count == 0) return; |
| - List otherList; |
| - int otherStart; |
| - if (from is List) { |
| - otherList = from; |
| - otherStart = skipCount; |
| - } else { |
| - otherList = from.skip(skipCount).toList(growable: false); |
| - otherStart = 0; |
| - } |
| - if (otherStart + count > otherList.length) { |
| - throw IterableElementError.tooFew(); |
| + List otherList; |
| + int otherStart; |
| + if (from is List) { |
| + otherList = from; |
| + otherStart = skipCount; |
| + } else { |
| + otherList = from.skip(skipCount).take(count).toList(growable: false); |
| + otherStart = 0; |
| + } |
| + if (otherStart + count > otherList.length) { |
| + throw IterableElementError.tooFew(); |
| + } |
| + Lists.copy(otherList, otherStart, this, start, count); |
| + return; |
| } |
| - Lists.copy(otherList, otherStart, this, start, count); |
| + assert(end != null); |
|
Søren Gjesse
2015/05/13 11:22:08
assert(start != null) as well for completeness.
Lasse Reichstein Nielsen
2015/05/18 12:21:08
The assert is only relevant because RangeError.che
|
| + // Guaranteed to fail. |
| + RangeError.checkValidRange(start, end, length); |
|
Søren Gjesse
2015/05/13 11:22:08
Add assert(false)?
Lasse Reichstein Nielsen
2015/05/18 12:21:09
Slightly icky, but ok.
|
| } |
| void setAll(int index, Iterable iterable) { |
| @@ -941,17 +933,18 @@ class _Int8Array extends _TypedList with _IntListMixin implements Int8List { |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
|
Ivan Posva
2015/05/14 18:13:18
Please do not change the style of the functions! H
Lasse Reichstein Nielsen
2015/05/18 12:21:09
This was a, possibly premature, attempt to improve
|
| + return _getInt8(index); |
| } |
| - return _getInt8(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setInt8(index, _toInt8(value)); |
| + return; |
| } |
| - _setInt8(index, _toInt8(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -982,17 +975,18 @@ class _Uint8Array extends _TypedList with _IntListMixin implements Uint8List { |
| // Methods implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getUint8(index); |
| } |
| - return _getUint8(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setUint8(index, _toUint8(value)); |
| + return; |
| } |
| - _setUint8(index, _toUint8(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1022,17 +1016,18 @@ class _Uint8ClampedArray extends _TypedList with _IntListMixin implements Uint8C |
| // Methods implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getUint8(index); |
| } |
| - return _getUint8(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setUint8(index, _toClampedUint8(value)); |
| + return; |
| } |
| - _setUint8(index, _toClampedUint8(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1064,17 +1059,18 @@ class _Int16Array extends _TypedList with _IntListMixin implements Int16List { |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt16(index); |
| } |
| - return _getIndexedInt16(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt16(index, _toInt16(value)); |
| + return; |
| } |
| - _setIndexedInt16(index, _toInt16(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| @@ -1124,17 +1120,18 @@ class _Uint16Array extends _TypedList with _IntListMixin implements Uint16List { |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedUint16(index); |
| } |
| - return _getIndexedUint16(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedUint16(index, _toUint16(value)); |
| + return; |
| } |
| - _setIndexedUint16(index, _toUint16(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| @@ -1184,17 +1181,18 @@ class _Int32Array extends _TypedList with _IntListMixin implements Int32List { |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt32(index); |
| } |
| - return _getIndexedInt32(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt32(index, _toInt32(value)); |
| + return; |
| } |
| - _setIndexedInt32(index, _toInt32(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1234,17 +1232,18 @@ class _Uint32Array extends _TypedList with _IntListMixin implements Uint32List { |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedUint32(index); |
| } |
| - return _getIndexedUint32(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedUint32(index, _toUint32(value)); |
| + return; |
| } |
| - _setIndexedUint32(index, _toUint32(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1284,17 +1283,18 @@ class _Int64Array extends _TypedList with _IntListMixin implements Int64List { |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt64(index); |
| } |
| - return _getIndexedInt64(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt64(index, _toInt64(value)); |
| + return; |
| } |
| - _setIndexedInt64(index, _toInt64(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1334,17 +1334,18 @@ class _Uint64Array extends _TypedList with _IntListMixin implements Uint64List { |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedUint64(index); |
| } |
| - return _getIndexedUint64(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedUint64(index, _toUint64(value)); |
| + return; |
| } |
| - _setIndexedUint64(index, _toUint64(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1384,17 +1385,18 @@ class _Float32Array extends _TypedList with _DoubleListMixin implements Float32L |
| // Method(s) implementing the List interface. |
| double operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat32(index); |
| } |
| - return _getIndexedFloat32(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, double value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat32(index, value); |
| + return; |
| } |
| - _setIndexedFloat32(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1434,17 +1436,18 @@ class _Float64Array extends _TypedList with _DoubleListMixin implements Float64L |
| // Method(s) implementing the List interface. |
| double operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat64(index); |
| } |
| - return _getIndexedFloat64(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, double value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat64(index, value); |
| + return; |
| } |
| - _setIndexedFloat64(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1482,17 +1485,18 @@ class _Float32x4Array extends _TypedList with _Float32x4ListMixin implements Flo |
| Float32x4 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat32x4(index); |
| } |
| - return _getIndexedFloat32x4(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Float32x4 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat32x4(index, value); |
| + return; |
| } |
| - _setIndexedFloat32x4(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1530,17 +1534,18 @@ class _Int32x4Array extends _TypedList with _Int32x4ListMixin implements Int32x4 |
| Int32x4 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt32x4(index); |
| } |
| - return _getIndexedInt32x4(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Int32x4 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt32x4(index, value); |
| + return; |
| } |
| - _setIndexedInt32x4(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1578,17 +1583,18 @@ class _Float64x2Array extends _TypedList with _Float64x2ListMixin implements Flo |
| Float64x2 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat64x2(index); |
| } |
| - return _getIndexedFloat64x2(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Float64x2 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat64x2(index, value); |
| + return; |
| } |
| - _setIndexedFloat64x2(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1627,17 +1633,18 @@ class _ExternalInt8Array extends _TypedList with _IntListMixin implements Int8Li |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getInt8(index); |
| } |
| - return _getInt8(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setInt8(index, value); |
| + return; |
| } |
| - _setInt8(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1670,17 +1677,18 @@ class _ExternalUint8Array extends _TypedList with _IntListMixin implements Uint8 |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getUint8(index); |
| } |
| - return _getUint8(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setUint8(index, _toUint8(value)); |
| + return; |
| } |
| - _setUint8(index, _toUint8(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1712,17 +1720,18 @@ class _ExternalUint8ClampedArray extends _TypedList with _IntListMixin implement |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getUint8(index); |
| } |
| - return _getUint8(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setUint8(index, _toClampedUint8(value)); |
| + return; |
| } |
| - _setUint8(index, _toClampedUint8(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1755,17 +1764,18 @@ class _ExternalInt16Array extends _TypedList with _IntListMixin implements Int16 |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt16(index); |
| } |
| - return _getIndexedInt16(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt16(index, _toInt16(value)); |
| + return; |
| } |
| - _setIndexedInt16(index, _toInt16(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1806,17 +1816,18 @@ class _ExternalUint16Array extends _TypedList with _IntListMixin implements Uint |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedUint16(index); |
| } |
| - return _getIndexedUint16(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedUint16(index, _toUint16(value)); |
| + return; |
| } |
| - _setIndexedUint16(index, _toUint16(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1857,17 +1868,18 @@ class _ExternalInt32Array extends _TypedList with _IntListMixin implements Int32 |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt32(index); |
| } |
| - return _getIndexedInt32(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt32(index, _toInt32(value)); |
| + return; |
| } |
| - _setIndexedInt32(index, _toInt32(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1908,17 +1920,18 @@ class _ExternalUint32Array extends _TypedList with _IntListMixin implements Uint |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedUint32(index); |
| } |
| - return _getIndexedUint32(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedUint32(index, _toUint32(value)); |
| + return; |
| } |
| - _setIndexedUint32(index, _toUint32(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -1959,17 +1972,18 @@ class _ExternalInt64Array extends _TypedList with _IntListMixin implements Int64 |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt64(index); |
| } |
| - return _getIndexedInt64(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt64(index, _toInt64(value)); |
| + return; |
| } |
| - _setIndexedInt64(index, _toInt64(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2010,17 +2024,18 @@ class _ExternalUint64Array extends _TypedList with _IntListMixin implements Uint |
| // Method(s) implementing the List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedUint64(index); |
| } |
| - return _getIndexedUint64(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedUint64(index, _toUint64(value)); |
| + return; |
| } |
| - _setIndexedUint64(index, _toUint64(value)); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2061,17 +2076,18 @@ class _ExternalFloat32Array extends _TypedList with _DoubleListMixin implements |
| // Method(s) implementing the List interface. |
| double operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat32(index); |
| } |
| - return _getIndexedFloat32(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, double value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat32(index, value); |
| + return; |
| } |
| - _setIndexedFloat32(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2112,17 +2128,18 @@ class _ExternalFloat64Array extends _TypedList with _DoubleListMixin implements |
| // Method(s) implementing the List interface. |
| double operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat64(index); |
| } |
| - return _getIndexedFloat64(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, double value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat64(index, value); |
| + return; |
| } |
| - _setIndexedFloat64(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2163,17 +2180,18 @@ class _ExternalFloat32x4Array extends _TypedList with _Float32x4ListMixin implem |
| // Method(s) implementing the List interface. |
| Float32x4 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat32x4(index); |
| } |
| - return _getIndexedFloat32x4(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Float32x4 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat32x4(index, value); |
| + return; |
| } |
| - _setIndexedFloat32x4(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2214,17 +2232,18 @@ class _ExternalInt32x4Array extends _TypedList with _Int32x4ListMixin implements |
| // Method(s) implementing the List interface. |
| Int32x4 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedInt32x4(index); |
| } |
| - return _getIndexedInt32x4(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Int32x4 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedInt32x4(index, value); |
| + return; |
| } |
| - _setIndexedInt32x4(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2265,17 +2284,18 @@ class _ExternalFloat64x2Array extends _TypedList with _Float64x2ListMixin implem |
| // Method(s) implementing the List interface. |
| Float64x2 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + return _getIndexedFloat64x2(index); |
| } |
| - return _getIndexedFloat64x2(index); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Float64x2 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| + if (index >= 0 && index < length) { |
| + _setIndexedFloat64x2(index, value); |
| + return; |
| } |
| - _setIndexedFloat64x2(index, value); |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2593,19 +2613,20 @@ class _Int8ArrayView extends _TypedListView with _IntListMixin implements Int8Li |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getInt8(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getInt8(offsetInBytes + |
| (index * Int8List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setInt8(offsetInBytes + (index * Int8List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setInt8(offsetInBytes + (index * Int8List.BYTES_PER_ELEMENT), |
| _toInt8(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2640,19 +2661,20 @@ class _Uint8ArrayView extends _TypedListView with _IntListMixin implements Uint8 |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getUint8(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getUint8(offsetInBytes + |
| (index * Uint8List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT), |
|
Søren Gjesse
2015/05/13 11:22:08
Long line - more below.
Lasse Reichstein Nielsen
2015/05/18 12:21:09
Done.
|
| _toUint8(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2688,19 +2710,20 @@ class _Uint8ClampedArrayView extends _TypedListView with _IntListMixin implement |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getUint8(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getUint8(offsetInBytes + |
| (index * Uint8List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setUint8(offsetInBytes + (index * Uint8List.BYTES_PER_ELEMENT), |
| _toClampedUint8(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2736,19 +2759,20 @@ class _Int16ArrayView extends _TypedListView with _IntListMixin implements Int16 |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getInt16(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getInt16(offsetInBytes + |
| (index * Int16List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setInt16(offsetInBytes + (index * Int16List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setInt16(offsetInBytes + (index * Int16List.BYTES_PER_ELEMENT), |
| _toInt16(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| @@ -2794,19 +2818,20 @@ class _Uint16ArrayView extends _TypedListView with _IntListMixin implements Uint |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getUint16(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getUint16(offsetInBytes + |
| (index * Uint16List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setUint16(offsetInBytes + (index * Uint16List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setUint16(offsetInBytes + (index * Uint16List.BYTES_PER_ELEMENT), |
| _toUint16(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void setRange(int start, int end, Iterable iterable, [int skipCount = 0]) { |
| @@ -2851,19 +2876,20 @@ class _Int32ArrayView extends _TypedListView with _IntListMixin implements Int32 |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getInt32(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getInt32(offsetInBytes + |
| (index * Int32List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setInt32(offsetInBytes + (index * Int32List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setInt32(offsetInBytes + (index * Int32List.BYTES_PER_ELEMENT), |
| _toInt32(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2899,19 +2925,20 @@ class _Uint32ArrayView extends _TypedListView with _IntListMixin implements Uint |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getUint32(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getUint32(offsetInBytes + |
| (index * Uint32List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setUint32(offsetInBytes + (index * Uint32List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setUint32(offsetInBytes + (index * Uint32List.BYTES_PER_ELEMENT), |
| _toUint32(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2947,19 +2974,20 @@ class _Int64ArrayView extends _TypedListView with _IntListMixin implements Int64 |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getInt64(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getInt64(offsetInBytes + |
| (index * Int64List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setInt64(offsetInBytes + (index * Int64List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setInt64(offsetInBytes + (index * Int64List.BYTES_PER_ELEMENT), |
| _toInt64(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -2995,19 +3023,20 @@ class _Uint64ArrayView extends _TypedListView with _IntListMixin implements Uint |
| // Method(s) implementing List interface. |
| int operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getUint64(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getUint64(offsetInBytes + |
| (index * Uint64List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, int value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setUint64(offsetInBytes + (index * Uint64List.BYTES_PER_ELEMENT), |
| + if (index >= 0 && index < length) { |
| + _typedData._setUint64(offsetInBytes + (index * Uint64List.BYTES_PER_ELEMENT), |
| _toUint64(value)); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -3043,19 +3072,20 @@ class _Float32ArrayView extends _TypedListView with _DoubleListMixin implements |
| // Method(s) implementing List interface. |
| double operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getFloat32(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getFloat32(offsetInBytes + |
| (index * Float32List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, double value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setFloat32(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + _typedData._setFloat32(offsetInBytes + |
| (index * Float32List.BYTES_PER_ELEMENT), value); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -3091,19 +3121,20 @@ class _Float64ArrayView extends _TypedListView with _DoubleListMixin implements |
| // Method(s) implementing List interface. |
| double operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getFloat64(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getFloat64(offsetInBytes + |
| (index * Float64List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, double value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setFloat64(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + _typedData._setFloat64(offsetInBytes + |
| (index * Float64List.BYTES_PER_ELEMENT), value); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -3139,19 +3170,20 @@ class _Float32x4ArrayView extends _TypedListView with _Float32x4ListMixin implem |
| // Method(s) implementing List interface. |
| Float32x4 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getFloat32x4(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getFloat32x4(offsetInBytes + |
| (index * Float32x4List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Float32x4 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setFloat32x4(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + _typedData._setFloat32x4(offsetInBytes + |
| (index * Float32x4List.BYTES_PER_ELEMENT), value); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -3187,19 +3219,20 @@ class _Int32x4ArrayView extends _TypedListView with _Int32x4ListMixin implements |
| // Method(s) implementing List interface. |
| Int32x4 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getInt32x4(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getInt32x4(offsetInBytes + |
| (index * Int32x4List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Int32x4 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setInt32x4(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + _typedData._setInt32x4(offsetInBytes + |
| (index * Int32x4List.BYTES_PER_ELEMENT), value); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -3235,19 +3268,20 @@ class _Float64x2ArrayView extends _TypedListView with _Float64x2ListMixin implem |
| // Method(s) implementing List interface. |
| Float64x2 operator[](int index) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - return _typedData._getFloat64x2(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + return _typedData._getFloat64x2(offsetInBytes + |
| (index * Float64x2List.BYTES_PER_ELEMENT)); |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| void operator[]=(int index, Float64x2 value) { |
| - if (index < 0 || index >= length) { |
| - throw _newRangeError(index, length); |
| - } |
| - _typedData._setFloat64x2(offsetInBytes + |
| + if (index >= 0 && index < length) { |
| + _typedData._setFloat64x2(offsetInBytes + |
| (index * Float64x2List.BYTES_PER_ELEMENT), value); |
| + return; |
| + } |
| + throw new RangeError.index(index, this, "index"); |
| } |
| @@ -3296,218 +3330,234 @@ class _ByteDataView implements ByteData { |
| // Method(s) implementing ByteData interface. |
| int getInt8(int byteOffset) { |
| - if (byteOffset < 0 || byteOffset >= length) { |
| - throw _newRangeError(byteOffset, length); |
| + if (byteOffset >= 0 && byteOffset < length) { |
| + return _typedData._getInt8(_offset + byteOffset); |
| } |
| - return _typedData._getInt8(_offset + byteOffset); |
| + throw new RangeError.index(byteOffset, this, "byteOffset"); |
| } |
| void setInt8(int byteOffset, int value) { |
| - if (byteOffset < 0 || byteOffset >= length) { |
| - throw _newRangeError(byteOffset, length); |
| + if (byteOffset >= 0 && byteOffset < length) { |
| + _typedData._setInt8(_offset + byteOffset, value); |
| + return; |
| } |
| - _typedData._setInt8(_offset + byteOffset, value); |
| + throw new RangeError.index(byteOffset, this, "byteOffset"); |
| } |
| int getUint8(int byteOffset) { |
| - if (byteOffset < 0 || byteOffset >= length) { |
| - throw _newRangeError(byteOffset, length); |
| + if (byteOffset >= 0 && byteOffset < length) { |
| + return _typedData._getUint8(_offset + byteOffset); |
| } |
| - return _typedData._getUint8(_offset + byteOffset); |
| + throw new RangeError.index(byteOffset, this, "byteOffset"); |
| } |
| void setUint8(int byteOffset, int value) { |
| - if (byteOffset < 0 || byteOffset >= length) { |
| - throw _newRangeError(byteOffset, length); |
| + if (byteOffset >= 0 && byteOffset < length) { |
| + _typedData._setUint8(_offset + byteOffset, value); |
| + return; |
| } |
| - _typedData._setUint8(_offset + byteOffset, value); |
| + throw new RangeError.index(byteOffset, this, "byteOffset"); |
| } |
| int getInt16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 1 >= length) { |
| - throw _newRangeError(byteOffset + 1, length); |
| - } |
| - var result = _typedData._getInt16(_offset + byteOffset); |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - return result; |
| + if (byteOffset >= 0 && byteOffset < length - 1) { |
| + var result = _typedData._getInt16(_offset + byteOffset); |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + return result; |
| + } |
| + return _byteSwap16(result).toSigned(16); |
| } |
| - return _byteSwap16(result).toSigned(16); |
| + throw new RangeError.range(byteOffset, 0, (length - 2), "byteOffset"); |
| } |
| void setInt16(int byteOffset, |
| int value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 1 >= length) { |
| - throw _newRangeError(byteOffset + 1, length); |
| + if (byteOffset >= 0 && byteOffset < length - 1) { |
| + _typedData._setInt16(_offset + byteOffset, |
| + identical(endian, Endianness.HOST_ENDIAN) ? value |
| + : _byteSwap16(value)); |
| + return; |
| } |
| - _typedData._setInt16(_offset + byteOffset, |
| - identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap16(value)); |
| + throw new RangeError.range(byteOffset, 0, (length - 2), "byteOffset"); |
| } |
| int getUint16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 1 >= length) { |
| - throw _newRangeError(byteOffset + 1, length); |
| - } |
| + if (byteOffset >= 0 && byteOffset < length - 1) { |
| var result = _typedData._getUint16(_offset + byteOffset); |
| if (identical(endian, Endianness.HOST_ENDIAN)) { |
| return result; |
| } |
| return _byteSwap16(result); |
| + } |
| + throw new RangeError.range(byteOffset, 0, (length - 2), "byteOffset"); |
| } |
| void setUint16(int byteOffset, |
| int value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 1 >= length) { |
| - throw _newRangeError(byteOffset + 1, length); |
| + if (byteOffset >= 0 && byteOffset < length - 1) { |
| + _typedData._setUint16(_offset + byteOffset, |
| + identical(endian, Endianness.HOST_ENDIAN) ? value |
| + : _byteSwap16(value)); |
| + return; |
| } |
| - _typedData._setUint16(_offset + byteOffset, |
| - identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap16(value)); |
| + throw new RangeError.range(byteOffset, 0, (length - 2), "byteOffset"); |
| } |
| int getInt32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| - } |
| - var result = _typedData._getInt32(_offset + byteOffset); |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - return result; |
| + if (byteOffset >= 0 && byteOffset < length - 3) { |
| + var result = _typedData._getInt32(_offset + byteOffset); |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + return result; |
| + } |
| + return _byteSwap32(result).toSigned(32); |
| } |
| - return _byteSwap32(result).toSigned(32); |
| + throw new RangeError.range(byteOffset, 0, length - 4); |
| } |
| void setInt32(int byteOffset, |
| int value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| + if (byteOffset >= 0 && byteOffset < length - 3) { |
| + _typedData._setInt32(_offset + byteOffset, |
| + identical(endian, Endianness.HOST_ENDIAN) ? value |
| + : _byteSwap32(value)); |
| + return; |
| } |
| - _typedData._setInt32(_offset + byteOffset, |
| - identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap32(value)); |
| + throw new RangeError.range(byteOffset, 0, length - 4); |
| } |
| int getUint32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| - } |
| - var result = _typedData._getUint32(_offset + byteOffset); |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - return result; |
| + if (byteOffset >= 0 && byteOffset < length - 3) { |
| + var result = _typedData._getUint32(_offset + byteOffset); |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + return result; |
| + } |
| + return _byteSwap32(result); |
| } |
| - return _byteSwap32(result); |
| + throw new RangeError.range(byteOffset, 0, length - 4); |
| } |
| void setUint32(int byteOffset, |
| int value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| + if (byteOffset >= 0 && byteOffset < length - 3) { |
| + _typedData._setUint32(_offset + byteOffset, |
| + identical(endian, Endianness.HOST_ENDIAN) ? value |
| + : _byteSwap32(value)); |
| + return; |
| } |
| - _typedData._setUint32(_offset + byteOffset, |
| - identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap32(value)); |
| + throw new RangeError.range(byteOffset, 0, length - 4); |
| } |
| int getInt64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 7 >= length) { |
| - throw _newRangeError(byteOffset + 7, length); |
| - } |
| - var result = _typedData._getInt64(_offset + byteOffset); |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - return result; |
| + if (byteOffset >= 0 && byteOffset < length - 7) { |
| + var result = _typedData._getInt64(_offset + byteOffset); |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + return result; |
| + } |
| + return _byteSwap64(result).toSigned(64); |
| } |
| - return _byteSwap64(result).toSigned(64); |
| + throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset"); |
| } |
| void setInt64(int byteOffset, |
| int value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 7 >= length) { |
| - throw _newRangeError(byteOffset + 7, length); |
| + if (byteOffset >= 0 && byteOffset < length - 7) { |
| + _typedData._setInt64(_offset + byteOffset, |
| + identical(endian, Endianness.HOST_ENDIAN) ? value |
| + : _byteSwap64(value)); |
| + return; |
| } |
| - _typedData._setInt64(_offset + byteOffset, |
| - identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap64(value)); |
| + throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset"); |
| } |
| int getUint64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 7 >= length) { |
| - throw _newRangeError(byteOffset + 7, length); |
| - } |
| - var result = _typedData._getUint64(_offset + byteOffset); |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - return result; |
| + if (byteOffset >= 0 && byteOffset < length - 7) { |
| + var result = _typedData._getUint64(_offset + byteOffset); |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + return result; |
| + } |
| + return _byteSwap64(result); |
| } |
| - return _byteSwap64(result); |
| + throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset"); |
| } |
| void setUint64(int byteOffset, |
| int value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 7 >= length) { |
| - throw _newRangeError(byteOffset + 7, length); |
| + if (byteOffset >= 0 && byteOffset < length - 7) { |
| + _typedData._setUint64(_offset + byteOffset, |
| + identical(endian, Endianness.HOST_ENDIAN) ? value |
| + : _byteSwap64(value)); |
| + return; |
| } |
| - _typedData._setUint64(_offset + byteOffset, |
| - identical(endian, Endianness.HOST_ENDIAN) ? value : _byteSwap64(value)); |
| + throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset"); |
| } |
| double getFloat32(int byteOffset, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| - } |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - return _typedData._getFloat32(_offset + byteOffset); |
| + if (byteOffset >= 0 && byteOffset < length - 3) { |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + return _typedData._getFloat32(_offset + byteOffset); |
| + } |
| + _convU32[0] = _byteSwap32(_typedData._getUint32(_offset + byteOffset)); |
| + return _convF32[0]; |
| } |
| - _convU32[0] = _byteSwap32(_typedData._getUint32(_offset + byteOffset)); |
| - return _convF32[0]; |
| + throw new RangeError(byteOffset, 0, length - 4, "byteOffset"); |
| } |
| void setFloat32(int byteOffset, |
| double value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| - } |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - _typedData._setFloat32(_offset + byteOffset, value); |
| + if (byteOffset >= 0 && byteOffset < length - 3) { |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + _typedData._setFloat32(_offset + byteOffset, value); |
| + return; |
| + } |
| + _convF32[0] = value; |
| + _typedData._setUint32(_offset + byteOffset, _byteSwap32(_convU32[0])); |
| return; |
| } |
| - _convF32[0] = value; |
| - _typedData._setUint32(_offset + byteOffset, _byteSwap32(_convU32[0])); |
| + throw new RangeError(byteOffset, 0, length - 4, "byteOffset"); |
| } |
| double getFloat64(int byteOffset, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 7 >= length) { |
| - throw _newRangeError(byteOffset + 7, length); |
| - } |
| - if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - return _typedData._getFloat64(_offset + byteOffset); |
| + if (byteOffset >= 0 && byteOffset < length - 7) { |
| + if (identical(endian, Endianness.HOST_ENDIAN)) { |
| + return _typedData._getFloat64(_offset + byteOffset); |
| + } |
| + _convU64[0] = _byteSwap64(_typedData._getUint64(_offset + byteOffset)); |
| + return _convF64[0]; |
| } |
| - _convU64[0] = _byteSwap64(_typedData._getUint64(_offset + byteOffset)); |
| - return _convF64[0]; |
| + throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset"); |
| } |
| void setFloat64(int byteOffset, |
| double value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 7 >= length) { |
| - throw _newRangeError(byteOffset + 7, length); |
| - } |
| + if (byteOffset >= 0 && byteOffset < length - 7) { |
| if (identical(endian, Endianness.HOST_ENDIAN)) { |
| - _typedData._setFloat64(_offset + byteOffset, value); |
| + _typedData._setFloat64(_offset + byteOffset, value); |
| + return; |
| + } |
| + _convF64[0] = value; |
| + _typedData._setUint64(_offset + byteOffset, _byteSwap64(_convU64[0])); |
| return; |
| } |
| - _convF64[0] = value; |
| - _typedData._setUint64(_offset + byteOffset, _byteSwap64(_convU64[0])); |
| + throw new RangeError.range(byteOffset, 0, length - 8, "byteOffset"); |
| } |
| Float32x4 getFloat32x4(int byteOffset, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| + if (byteOffset >= 0 && byteOffset < length - 15) { |
| + // TODO(johnmccutchan) : Need to resolve this for endianity. |
| + return _typedData._getFloat32x4(_offset + byteOffset); |
| } |
| - // TODO(johnmccutchan) : Need to resolve this for endianity. |
| - return _typedData._getFloat32x4(_offset + byteOffset); |
| + throw new RangeError.range(byteOffset, 0, length - 16, "byteOffset"); |
| } |
| void setFloat32x4(int byteOffset, |
| Float32x4 value, |
| [Endianness endian = Endianness.BIG_ENDIAN]) { |
| - if (byteOffset < 0 || byteOffset + 3 >= length) { |
| - throw _newRangeError(byteOffset + 3, length); |
| + if (byteOffset >= 0 && byteOffset < length - 15) { |
| + // TODO(johnmccutchan) : Need to resolve this for endianity. |
| + _typedData._setFloat32x4(_offset + byteOffset, value); |
| + return; |
| } |
| - // TODO(johnmccutchan) : Need to resolve this for endianity. |
| - _typedData._setFloat32x4(_offset + byteOffset, value); |
| - |
| + throw new RangeError.range(byteOffset, 0, length - 16, "byteOffset"); |
| } |
| final TypedData _typedData; |
| @@ -3621,9 +3671,3 @@ int _defaultIfNull(object, value) { |
| } |
| return object; |
| } |
| - |
| - |
| -_newRangeError(int index, int length) { |
| - String message = "$index must be in the range [0..$length)"; |
| - return new RangeError(message); |
| -} |