Updated {,unmodifiable_}typed_data.dart for NNBD.

This CL updates typed_data.dart and unmodifiable_typed_data.dart such
that there are no issues from the dartanalyzer, non-nullable, in the
context of 103124, apart from conflicting_generic_interfaces, cf. SDK
issue #38813.

It updates _internal/js_dev_runtime/patch/typed_data_patch.dart and
_internal/vm/lib/typed_data_patch.dart with respect to the members
whose signatures were changed in the ...typed_data.dart libraries.

It updates lib/collection.list at member signatures, in order to
allow subtypes in ...typed_data to override a member with an NNBD-
correct signature: `contains`, `lastIndexOf`, `lastIndexWhere`. The
body of said members was adjusted to make it work in an NNBD setting.

Change-Id: Idbdd738834d70f408f6b4d65fcbacde28abb8d15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121280
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Erik Ernst 2019-10-25 07:34:34 +00:00 committed by commit-bot@chromium.org
parent 81a2925ac2
commit 5a45d0b062
4 changed files with 169 additions and 180 deletions

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.5
import 'dart:collection';
import 'dart:_js_helper' show patch;
import 'dart:_native_typed_data';

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.5
/// Note: the VM concatenates all patch files into a single patch file. This
/// file is the first patch in "dart:typed_data" which contains all the imports
/// used by patches of that library. We plan to change this when we have a
@ -142,9 +140,10 @@ mixin _IntListMixin implements List<int> {
return -1;
}
int lastIndexWhere(bool test(int element), [int start]) {
if (start == null || start >= this.length) start = this.length - 1;
for (int i = start; i >= 0; i--) {
int lastIndexWhere(bool test(int element), [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (test(this[i])) return i;
}
return -1;
@ -166,7 +165,7 @@ mixin _IntListMixin implements List<int> {
return false;
}
void shuffle([Random random]) {
void shuffle([Random? random]) {
random ??= new Random();
var i = this.length;
while (i > 1) {
@ -194,9 +193,9 @@ mixin _IntListMixin implements List<int> {
Map<int, int> asMap() => new ListMapView<int>(this);
Iterable<int> getRange(int start, [int end]) {
RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<int>(this, start, end);
Iterable<int> getRange(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<int>(this, start, endIndex);
}
Iterator<int> get iterator => new _TypedListIterator<int>(this);
@ -316,7 +315,7 @@ mixin _IntListMixin implements List<int> {
throw new UnsupportedError("Cannot insert into a fixed-length list");
}
void sort([int compare(int a, int b)]) {
void sort([int compare(int a, int b)?]) {
Sort.sort(this, compare ?? Comparable.compare);
}
@ -332,13 +331,10 @@ mixin _IntListMixin implements List<int> {
return -1;
}
int lastIndexOf(int element, [int start = null]) {
if (start == null || start >= this.length) {
start = this.length - 1;
} else if (start < 0) {
return -1;
}
for (int i = start; i >= 0; i--) {
int lastIndexOf(int element, [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (this[i] == element) return i;
}
return -1;
@ -381,7 +377,8 @@ mixin _IntListMixin implements List<int> {
setRange(index, end, iterable);
}
void fillRange(int start, int end, [int fillValue]) {
void fillRange(int start, int end, [int? fillValue]) {
if (fillValue == null) throw ArgumentError.notNull("fillValue");
RangeError.checkValidRange(start, end, this.length);
for (var i = start; i < end; ++i) {
this[i] = fillValue;
@ -458,9 +455,9 @@ mixin _TypedIntListMixin<SpawnedType extends List<int>> on _IntListMixin
Lists.copy(otherList, otherStart, this, start, count);
}
SpawnedType sublist(int start, [int end]) {
end = RangeError.checkValidRange(start, end, this.length);
var length = end - start;
SpawnedType sublist(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
var length = endIndex - start;
SpawnedType result = _createList(length);
result.setRange(0, length, this, start);
return result;
@ -496,9 +493,10 @@ mixin _DoubleListMixin implements List<double> {
return -1;
}
int lastIndexWhere(bool test(double element), [int start]) {
if (start == null || start >= this.length) start = this.length - 1;
for (int i = start; i >= 0; i--) {
int lastIndexWhere(bool test(double element), [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (test(this[i])) return i;
}
return -1;
@ -520,7 +518,7 @@ mixin _DoubleListMixin implements List<double> {
return false;
}
void shuffle([Random random]) {
void shuffle([Random? random]) {
random ??= new Random();
var i = this.length;
while (i > 1) {
@ -549,9 +547,9 @@ mixin _DoubleListMixin implements List<double> {
Map<int, double> asMap() => new ListMapView<double>(this);
Iterable<double> getRange(int start, [int end]) {
RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<double>(this, start, end);
Iterable<double> getRange(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<double>(this, start, endIndex);
}
Iterator<double> get iterator => new _TypedListIterator<double>(this);
@ -672,7 +670,7 @@ mixin _DoubleListMixin implements List<double> {
throw new UnsupportedError("Cannot insert into a fixed-length list");
}
void sort([int compare(double a, double b)]) {
void sort([int compare(double a, double b)?]) {
Sort.sort(this, compare ?? Comparable.compare);
}
@ -688,13 +686,10 @@ mixin _DoubleListMixin implements List<double> {
return -1;
}
int lastIndexOf(double element, [int start = null]) {
if (start == null || start >= this.length) {
start = this.length - 1;
} else if (start < 0) {
return -1;
}
for (int i = start; i >= 0; i--) {
int lastIndexOf(double element, [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (this[i] == element) return i;
}
return -1;
@ -737,7 +732,9 @@ mixin _DoubleListMixin implements List<double> {
setRange(index, end, iterable);
}
void fillRange(int start, int end, [double fillValue]) {
void fillRange(int start, int end, [double? fillValue]) {
// TODO(eernst): Could use zero as default and not throw; issue .
if (fillValue == null) throw ArgumentError.notNull("fillValue");
RangeError.checkValidRange(start, end, this.length);
for (var i = start; i < end; ++i) {
this[i] = fillValue;
@ -815,9 +812,9 @@ mixin _TypedDoubleListMixin<SpawnedType extends List<double>>
Lists.copy(otherList, otherStart, this, start, count);
}
SpawnedType sublist(int start, [int end]) {
end = RangeError.checkValidRange(start, end, this.length);
var length = end - start;
SpawnedType sublist(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
var length = endIndex - start;
SpawnedType result = _createList(length);
result.setRange(0, length, this, start);
return result;
@ -855,9 +852,10 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
return -1;
}
int lastIndexWhere(bool test(Float32x4 element), [int start]) {
if (start == null || start >= this.length) start = this.length - 1;
for (int i = start; i >= 0; i--) {
int lastIndexWhere(bool test(Float32x4 element), [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (test(this[i])) return i;
}
return -1;
@ -879,7 +877,7 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
return false;
}
void shuffle([Random random]) {
void shuffle([Random? random]) {
random ??= new Random();
var i = this.length;
while (i > 1) {
@ -975,9 +973,9 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
Map<int, Float32x4> asMap() => new ListMapView<Float32x4>(this);
Iterable<Float32x4> getRange(int start, [int end]) {
RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<Float32x4>(this, start, end);
Iterable<Float32x4> getRange(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<Float32x4>(this, start, endIndex);
}
Iterator<Float32x4> get iterator => new _TypedListIterator<Float32x4>(this);
@ -1098,7 +1096,7 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
throw new UnsupportedError("Cannot insert into a fixed-length list");
}
void sort([int compare(Float32x4 a, Float32x4 b)]) {
void sort([int compare(Float32x4 a, Float32x4 b)?]) {
if (compare == null) {
throw "SIMD don't have default compare.";
}
@ -1117,13 +1115,10 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
return -1;
}
int lastIndexOf(Float32x4 element, [int start = null]) {
if (start == null || start >= this.length) {
start = this.length - 1;
} else if (start < 0) {
return -1;
}
for (int i = start; i >= 0; i--) {
int lastIndexOf(Float32x4 element, [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (this[i] == element) return i;
}
return -1;
@ -1161,9 +1156,9 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
throw IterableElementError.tooMany();
}
Float32x4List sublist(int start, [int end]) {
end = RangeError.checkValidRange(start, end, this.length);
var length = end - start;
Float32x4List sublist(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
var length = endIndex - start;
Float32x4List result = _createList(length);
result.setRange(0, length, this, start);
return result;
@ -1174,7 +1169,8 @@ abstract class _Float32x4ListMixin implements List<Float32x4> {
setRange(index, end, iterable);
}
void fillRange(int start, int end, [Float32x4 fillValue]) {
void fillRange(int start, int end, [Float32x4? fillValue]) {
if (fillValue == null) throw ArgumentError.notNull("fillValue");
RangeError.checkValidRange(start, end, this.length);
for (var i = start; i < end; ++i) {
this[i] = fillValue;
@ -1213,9 +1209,10 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
return -1;
}
int lastIndexWhere(bool test(Int32x4 element), [int start]) {
if (start == null || start >= this.length) start = this.length - 1;
for (int i = start; i >= 0; i--) {
int lastIndexWhere(bool test(Int32x4 element), [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (test(this[i])) return i;
}
return -1;
@ -1237,7 +1234,7 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
return false;
}
void shuffle([Random random]) {
void shuffle([Random? random]) {
random ??= new Random();
var i = this.length;
while (i > 1) {
@ -1332,9 +1329,9 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
Map<int, Int32x4> asMap() => new ListMapView<Int32x4>(this);
Iterable<Int32x4> getRange(int start, [int end]) {
RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<Int32x4>(this, start, end);
Iterable<Int32x4> getRange(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<Int32x4>(this, start, endIndex);
}
Iterator<Int32x4> get iterator => new _TypedListIterator<Int32x4>(this);
@ -1455,7 +1452,7 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
throw new UnsupportedError("Cannot insert into a fixed-length list");
}
void sort([int compare(Int32x4 a, Int32x4 b)]) {
void sort([int compare(Int32x4 a, Int32x4 b)?]) {
if (compare == null) {
throw "SIMD don't have default compare.";
}
@ -1474,13 +1471,10 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
return -1;
}
int lastIndexOf(Int32x4 element, [int start = null]) {
if (start == null || start >= this.length) {
start = this.length - 1;
} else if (start < 0) {
return -1;
}
for (int i = start; i >= 0; i--) {
int lastIndexOf(Int32x4 element, [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (this[i] == element) return i;
}
return -1;
@ -1518,9 +1512,9 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
throw IterableElementError.tooMany();
}
Int32x4List sublist(int start, [int end]) {
end = RangeError.checkValidRange(start, end, this.length);
var length = end - start;
Int32x4List sublist(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
var length = endIndex - start;
Int32x4List result = _createList(length);
result.setRange(0, length, this, start);
return result;
@ -1531,7 +1525,8 @@ abstract class _Int32x4ListMixin implements List<Int32x4> {
setRange(index, end, iterable);
}
void fillRange(int start, int end, [Int32x4 fillValue]) {
void fillRange(int start, int end, [Int32x4? fillValue]) {
if (fillValue == null) throw ArgumentError.notNull("fillValue");
RangeError.checkValidRange(start, end, this.length);
for (var i = start; i < end; ++i) {
this[i] = fillValue;
@ -1570,9 +1565,10 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
return -1;
}
int lastIndexWhere(bool test(Float64x2 element), [int start]) {
if (start == null || start >= this.length) start = this.length - 1;
for (int i = start; i >= 0; i--) {
int lastIndexWhere(bool test(Float64x2 element), [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (test(this[i])) return i;
}
return -1;
@ -1594,7 +1590,7 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
return false;
}
void shuffle([Random random]) {
void shuffle([Random? random]) {
random ??= new Random();
var i = this.length;
while (i > 1) {
@ -1690,9 +1686,9 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
Map<int, Float64x2> asMap() => new ListMapView<Float64x2>(this);
Iterable<Float64x2> getRange(int start, [int end]) {
RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<Float64x2>(this, start, end);
Iterable<Float64x2> getRange(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
return new SubListIterable<Float64x2>(this, start, endIndex);
}
Iterator<Float64x2> get iterator => new _TypedListIterator<Float64x2>(this);
@ -1813,7 +1809,7 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
throw new UnsupportedError("Cannot insert into a fixed-length list");
}
void sort([int compare(Float64x2 a, Float64x2 b)]) {
void sort([int compare(Float64x2 a, Float64x2 b)?]) {
if (compare == null) {
throw "SIMD don't have default compare.";
}
@ -1832,13 +1828,10 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
return -1;
}
int lastIndexOf(Float64x2 element, [int start = null]) {
if (start == null || start >= this.length) {
start = this.length - 1;
} else if (start < 0) {
return -1;
}
for (int i = start; i >= 0; i--) {
int lastIndexOf(Float64x2 element, [int? start]) {
int startIndex =
(start == null || start >= this.length) ? this.length - 1 : start;
for (int i = startIndex; i >= 0; i--) {
if (this[i] == element) return i;
}
return -1;
@ -1876,9 +1869,9 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
throw IterableElementError.tooMany();
}
Float64x2List sublist(int start, [int end]) {
end = RangeError.checkValidRange(start, end, this.length);
var length = end - start;
Float64x2List sublist(int start, [int? end]) {
int endIndex = RangeError.checkValidRange(start, end, this.length);
var length = endIndex - start;
Float64x2List result = _createList(length);
result.setRange(0, length, this, start);
return result;
@ -1889,7 +1882,8 @@ abstract class _Float64x2ListMixin implements List<Float64x2> {
setRange(index, end, iterable);
}
void fillRange(int start, int end, [Float64x2 fillValue]) {
void fillRange(int start, int end, [Float64x2? fillValue]) {
if (fillValue == null) throw ArgumentError.notNull("fillValue");
RangeError.checkValidRange(start, end, this.length);
for (var i = start; i < end; ++i) {
this[i] = fillValue;
@ -1912,20 +1906,20 @@ class _ByteBuffer implements ByteBuffer {
bool operator ==(Object other) =>
(other is _ByteBuffer) && identical(_data, other._data);
ByteData asByteData([int offsetInBytes = 0, int length]) {
ByteData asByteData([int offsetInBytes = 0, int? length]) {
length ??= this.lengthInBytes - offsetInBytes;
_rangeCheck(this._data.lengthInBytes, offsetInBytes, length);
return new _ByteDataView._(this._data, offsetInBytes, length);
}
Int8List asInt8List([int offsetInBytes = 0, int length]) {
Int8List asInt8List([int offsetInBytes = 0, int? length]) {
length ??= (this.lengthInBytes - offsetInBytes) ~/ Int8List.bytesPerElement;
_rangeCheck(
this.lengthInBytes, offsetInBytes, length * Int8List.bytesPerElement);
return new _Int8ArrayView._(this._data, offsetInBytes, length);
}
Uint8List asUint8List([int offsetInBytes = 0, int length]) {
Uint8List asUint8List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Uint8List.bytesPerElement;
_rangeCheck(
@ -1933,7 +1927,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Uint8ArrayView._(this._data, offsetInBytes, length);
}
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]) {
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]) {
length ??= (this.lengthInBytes - offsetInBytes) ~/
Uint8ClampedList.bytesPerElement;
_rangeCheck(this.lengthInBytes, offsetInBytes,
@ -1941,7 +1935,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Uint8ClampedArrayView._(this._data, offsetInBytes, length);
}
Int16List asInt16List([int offsetInBytes = 0, int length]) {
Int16List asInt16List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Int16List.bytesPerElement;
_rangeCheck(
@ -1950,7 +1944,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Int16ArrayView._(this._data, offsetInBytes, length);
}
Uint16List asUint16List([int offsetInBytes = 0, int length]) {
Uint16List asUint16List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Uint16List.bytesPerElement;
_rangeCheck(
@ -1959,7 +1953,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Uint16ArrayView._(this._data, offsetInBytes, length);
}
Int32List asInt32List([int offsetInBytes = 0, int length]) {
Int32List asInt32List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Int32List.bytesPerElement;
_rangeCheck(
@ -1968,7 +1962,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Int32ArrayView._(this._data, offsetInBytes, length);
}
Uint32List asUint32List([int offsetInBytes = 0, int length]) {
Uint32List asUint32List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Uint32List.bytesPerElement;
_rangeCheck(
@ -1977,7 +1971,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Uint32ArrayView._(this._data, offsetInBytes, length);
}
Int64List asInt64List([int offsetInBytes = 0, int length]) {
Int64List asInt64List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Int64List.bytesPerElement;
_rangeCheck(
@ -1986,7 +1980,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Int64ArrayView._(this._data, offsetInBytes, length);
}
Uint64List asUint64List([int offsetInBytes = 0, int length]) {
Uint64List asUint64List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Uint64List.bytesPerElement;
_rangeCheck(
@ -1995,7 +1989,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Uint64ArrayView._(this._data, offsetInBytes, length);
}
Float32List asFloat32List([int offsetInBytes = 0, int length]) {
Float32List asFloat32List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Float32List.bytesPerElement;
_rangeCheck(this.lengthInBytes, offsetInBytes,
@ -2004,7 +1998,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Float32ArrayView._(this._data, offsetInBytes, length);
}
Float64List asFloat64List([int offsetInBytes = 0, int length]) {
Float64List asFloat64List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Float64List.bytesPerElement;
_rangeCheck(this.lengthInBytes, offsetInBytes,
@ -2013,7 +2007,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Float64ArrayView._(this._data, offsetInBytes, length);
}
Float32x4List asFloat32x4List([int offsetInBytes = 0, int length]) {
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Float32x4List.bytesPerElement;
_rangeCheck(this.lengthInBytes, offsetInBytes,
@ -2022,7 +2016,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Float32x4ArrayView._(this._data, offsetInBytes, length);
}
Int32x4List asInt32x4List([int offsetInBytes = 0, int length]) {
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Int32x4List.bytesPerElement;
_rangeCheck(this.lengthInBytes, offsetInBytes,
@ -2031,7 +2025,7 @@ class _ByteBuffer implements ByteBuffer {
return new _Int32x4ArrayView._(this._data, offsetInBytes, length);
}
Float64x2List asFloat64x2List([int offsetInBytes = 0, int length]) {
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]) {
length ??=
(this.lengthInBytes - offsetInBytes) ~/ Float64x2List.bytesPerElement;
_rangeCheck(this.lengthInBytes, offsetInBytes,

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.5
/// Lists that efficiently handle fixed sized data
/// (for example, unsigned 8 byte integers) and SIMD numeric types.
///
@ -46,7 +44,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length` must not be greater than [lengthInBytes].
*/
Uint8List asUint8List([int offsetInBytes = 0, int length]);
Uint8List asUint8List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Int8List] _view_ of a region of this byte buffer.
@ -64,7 +62,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length` must not be greater than [lengthInBytes].
*/
Int8List asInt8List([int offsetInBytes = 0, int length]);
Int8List asInt8List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Uint8ClampedList] _view_ of a region of this byte buffer.
@ -82,7 +80,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length` must not be greater than [lengthInBytes].
*/
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]);
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]);
/**
* Creates a [Uint16List] _view_ of a region of this byte buffer.
@ -105,7 +103,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 2` must not be greater than [lengthInBytes].
*/
Uint16List asUint16List([int offsetInBytes = 0, int length]);
Uint16List asUint16List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Int16List] _view_ of a region of this byte buffer.
@ -128,7 +126,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 2` must not be greater than [lengthInBytes].
*/
Int16List asInt16List([int offsetInBytes = 0, int length]);
Int16List asInt16List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Uint32List] _view_ of a region of this byte buffer.
@ -152,7 +150,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 4` must not be greater than [lengthInBytes].
*/
Uint32List asUint32List([int offsetInBytes = 0, int length]);
Uint32List asUint32List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Int32List] _view_ of a region of this byte buffer.
@ -176,7 +174,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 4` must not be greater than [lengthInBytes].
*/
Int32List asInt32List([int offsetInBytes = 0, int length]);
Int32List asInt32List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Uint64List] _view_ of a region of this byte buffer.
@ -200,7 +198,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 8` must not be greater than [lengthInBytes].
*/
Uint64List asUint64List([int offsetInBytes = 0, int length]);
Uint64List asUint64List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Int64List] _view_ of a region of this byte buffer.
@ -224,7 +222,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 8` must not be greater than [lengthInBytes].
*/
Int64List asInt64List([int offsetInBytes = 0, int length]);
Int64List asInt64List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Int32x4List] _view_ of a region of this byte buffer.
@ -248,7 +246,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 16` must not be greater than [lengthInBytes].
*/
Int32x4List asInt32x4List([int offsetInBytes = 0, int length]);
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Float32List] _view_ of a region of this byte buffer.
@ -272,7 +270,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 4` must not be greater than [lengthInBytes].
*/
Float32List asFloat32List([int offsetInBytes = 0, int length]);
Float32List asFloat32List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Float64List] _view_ of a region of this byte buffer.
@ -296,7 +294,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 8` must not be greater than [lengthInBytes].
*/
Float64List asFloat64List([int offsetInBytes = 0, int length]);
Float64List asFloat64List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Float32x4List] _view_ of a region of this byte buffer.
@ -320,7 +318,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 16` must not be greater than [lengthInBytes].
*/
Float32x4List asFloat32x4List([int offsetInBytes = 0, int length]);
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]);
/**
* Creates a [Float64x2List] _view_ of a region of this byte buffer.
@ -344,7 +342,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length * 16` must not be greater than [lengthInBytes].
*/
Float64x2List asFloat64x2List([int offsetInBytes = 0, int length]);
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]);
/**
* Creates a [ByteData] _view_ of a region of this byte buffer.
@ -362,7 +360,7 @@ abstract class ByteBuffer {
* * `length` must not be negative, and
* * `offsetInBytes + length` must not be greater than [lengthInBytes].
*/
ByteData asByteData([int offsetInBytes = 0, int length]);
ByteData asByteData([int offsetInBytes = 0, int? length]);
}
/**
@ -475,7 +473,7 @@ abstract class ByteData implements TypedData {
* the length of [buffer].
*/
factory ByteData.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asByteData(offsetInBytes, length);
}
@ -770,7 +768,7 @@ abstract class Int8List implements List<int>, _TypedIntList {
* the length of [buffer].
*/
factory Int8List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asInt8List(offsetInBytes, length);
}
@ -797,7 +795,7 @@ abstract class Int8List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Int8List sublist(int start, [int end]);
Int8List sublist(int start, [int? end]);
static const int bytesPerElement = 1;
}
@ -843,7 +841,7 @@ abstract class Uint8List implements List<int>, _TypedIntList {
* the length of [buffer].
*/
factory Uint8List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asUint8List(offsetInBytes, length);
}
@ -879,7 +877,7 @@ abstract class Uint8List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Uint8List sublist(int start, [int end]);
Uint8List sublist(int start, [int? end]);
static const int bytesPerElement = 1;
}
@ -926,7 +924,7 @@ abstract class Uint8ClampedList implements List<int>, _TypedIntList {
* the length of [buffer].
*/
factory Uint8ClampedList.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asUint8ClampedList(offsetInBytes, length);
}
@ -953,7 +951,7 @@ abstract class Uint8ClampedList implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Uint8ClampedList sublist(int start, [int end]);
Uint8ClampedList sublist(int start, [int? end]);
static const int bytesPerElement = 1;
}
@ -1003,7 +1001,7 @@ abstract class Int16List implements List<int>, _TypedIntList {
* [bytesPerElement].
*/
factory Int16List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asInt16List(offsetInBytes, length);
}
@ -1030,7 +1028,7 @@ abstract class Int16List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Int16List sublist(int start, [int end]);
Int16List sublist(int start, [int? end]);
static const int bytesPerElement = 2;
}
@ -1081,7 +1079,7 @@ abstract class Uint16List implements List<int>, _TypedIntList {
* [bytesPerElement].
*/
factory Uint16List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asUint16List(offsetInBytes, length);
}
@ -1108,7 +1106,7 @@ abstract class Uint16List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Uint16List sublist(int start, [int end]);
Uint16List sublist(int start, [int? end]);
static const int bytesPerElement = 2;
}
@ -1158,7 +1156,7 @@ abstract class Int32List implements List<int>, _TypedIntList {
* [bytesPerElement].
*/
factory Int32List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asInt32List(offsetInBytes, length);
}
@ -1185,7 +1183,7 @@ abstract class Int32List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Int32List sublist(int start, [int end]);
Int32List sublist(int start, [int? end]);
static const int bytesPerElement = 4;
}
@ -1236,7 +1234,7 @@ abstract class Uint32List implements List<int>, _TypedIntList {
* [bytesPerElement].
*/
factory Uint32List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asUint32List(offsetInBytes, length);
}
@ -1263,7 +1261,7 @@ abstract class Uint32List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Uint32List sublist(int start, [int end]);
Uint32List sublist(int start, [int? end]);
static const int bytesPerElement = 4;
}
@ -1313,7 +1311,7 @@ abstract class Int64List implements List<int>, _TypedIntList {
* [bytesPerElement].
*/
factory Int64List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asInt64List(offsetInBytes, length);
}
@ -1340,7 +1338,7 @@ abstract class Int64List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Int64List sublist(int start, [int end]);
Int64List sublist(int start, [int? end]);
static const int bytesPerElement = 8;
}
@ -1391,7 +1389,7 @@ abstract class Uint64List implements List<int>, _TypedIntList {
* [bytesPerElement].
*/
factory Uint64List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asUint64List(offsetInBytes, length);
}
@ -1418,7 +1416,7 @@ abstract class Uint64List implements List<int>, _TypedIntList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Uint64List sublist(int start, [int end]);
Uint64List sublist(int start, [int? end]);
static const int bytesPerElement = 8;
}
@ -1469,7 +1467,7 @@ abstract class Float32List implements List<double>, _TypedFloatList {
* [bytesPerElement].
*/
factory Float32List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asFloat32List(offsetInBytes, length);
}
@ -1496,7 +1494,7 @@ abstract class Float32List implements List<double>, _TypedFloatList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Float32List sublist(int start, [int end]);
Float32List sublist(int start, [int? end]);
static const int bytesPerElement = 4;
}
@ -1540,7 +1538,7 @@ abstract class Float64List implements List<double>, _TypedFloatList {
* [bytesPerElement].
*/
factory Float64List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asFloat64List(offsetInBytes, length);
}
@ -1567,7 +1565,7 @@ abstract class Float64List implements List<double>, _TypedFloatList {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Float64List sublist(int start, [int end]);
Float64List sublist(int start, [int? end]);
static const int bytesPerElement = 8;
}
@ -1610,7 +1608,7 @@ abstract class Float32x4List implements List<Float32x4>, TypedData {
* [bytesPerElement].
*/
factory Float32x4List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asFloat32x4List(offsetInBytes, length);
}
@ -1645,7 +1643,7 @@ abstract class Float32x4List implements List<Float32x4>, TypedData {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Float32x4List sublist(int start, [int end]);
Float32x4List sublist(int start, [int? end]);
static const int bytesPerElement = 16;
}
@ -1688,7 +1686,7 @@ abstract class Int32x4List implements List<Int32x4>, TypedData {
* [bytesPerElement].
*/
factory Int32x4List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asInt32x4List(offsetInBytes, length);
}
@ -1723,7 +1721,7 @@ abstract class Int32x4List implements List<Int32x4>, TypedData {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Int32x4List sublist(int start, [int end]);
Int32x4List sublist(int start, [int? end]);
static const int bytesPerElement = 16;
}
@ -1774,7 +1772,7 @@ abstract class Float64x2List implements List<Float64x2>, TypedData {
* [bytesPerElement].
*/
factory Float64x2List.view(ByteBuffer buffer,
[int offsetInBytes = 0, int length]) {
[int offsetInBytes = 0, int? length]) {
return buffer.asFloat64x2List(offsetInBytes, length);
}
@ -1801,7 +1799,7 @@ abstract class Float64x2List implements List<Float64x2>, TypedData {
* 0 `start` `end` `this.length`
* If `end` is equal to `start`, then the returned list is empty.
*/
Float64x2List sublist(int start, [int end]);
Float64x2List sublist(int start, [int? end]);
static const int bytesPerElement = 16;
}

View file

@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.5
part of dart.typed_data;
/**
@ -16,55 +14,55 @@ class UnmodifiableByteBufferView implements ByteBuffer {
int get lengthInBytes => _data.lengthInBytes;
Uint8List asUint8List([int offsetInBytes = 0, int length]) =>
Uint8List asUint8List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableUint8ListView(_data.asUint8List(offsetInBytes, length));
Int8List asInt8List([int offsetInBytes = 0, int length]) =>
Int8List asInt8List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableInt8ListView(_data.asInt8List(offsetInBytes, length));
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]) =>
Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int? length]) =>
new UnmodifiableUint8ClampedListView(
_data.asUint8ClampedList(offsetInBytes, length));
Uint16List asUint16List([int offsetInBytes = 0, int length]) =>
Uint16List asUint16List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableUint16ListView(_data.asUint16List(offsetInBytes, length));
Int16List asInt16List([int offsetInBytes = 0, int length]) =>
Int16List asInt16List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableInt16ListView(_data.asInt16List(offsetInBytes, length));
Uint32List asUint32List([int offsetInBytes = 0, int length]) =>
Uint32List asUint32List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableUint32ListView(_data.asUint32List(offsetInBytes, length));
Int32List asInt32List([int offsetInBytes = 0, int length]) =>
Int32List asInt32List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableInt32ListView(_data.asInt32List(offsetInBytes, length));
Uint64List asUint64List([int offsetInBytes = 0, int length]) =>
Uint64List asUint64List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableUint64ListView(_data.asUint64List(offsetInBytes, length));
Int64List asInt64List([int offsetInBytes = 0, int length]) =>
Int64List asInt64List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableInt64ListView(_data.asInt64List(offsetInBytes, length));
Int32x4List asInt32x4List([int offsetInBytes = 0, int length]) =>
Int32x4List asInt32x4List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableInt32x4ListView(
_data.asInt32x4List(offsetInBytes, length));
Float32List asFloat32List([int offsetInBytes = 0, int length]) =>
Float32List asFloat32List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableFloat32ListView(
_data.asFloat32List(offsetInBytes, length));
Float64List asFloat64List([int offsetInBytes = 0, int length]) =>
Float64List asFloat64List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableFloat64ListView(
_data.asFloat64List(offsetInBytes, length));
Float32x4List asFloat32x4List([int offsetInBytes = 0, int length]) =>
Float32x4List asFloat32x4List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableFloat32x4ListView(
_data.asFloat32x4List(offsetInBytes, length));
Float64x2List asFloat64x2List([int offsetInBytes = 0, int length]) =>
Float64x2List asFloat64x2List([int offsetInBytes = 0, int? length]) =>
new UnmodifiableFloat64x2ListView(
_data.asFloat64x2List(offsetInBytes, length));
ByteData asByteData([int offsetInBytes = 0, int length]) =>
ByteData asByteData([int offsetInBytes = 0, int? length]) =>
new UnmodifiableByteDataView(_data.asByteData(offsetInBytes, length));
}
@ -165,9 +163,10 @@ abstract class _UnmodifiableListMixin<N, L extends List<N>,
L _createList(int length);
L sublist(int start, [int end]) {
end = RangeError.checkValidRange(start, end, length);
int sublistLength = end - start;
L sublist(int start, [int? end]) {
// NNBD: Spurious error at `end`, `checkValidRange` is legacy.
int endIndex = RangeError.checkValidRange(start, end!, length);
int sublistLength = endIndex - start;
L result = _createList(sublistLength);
result.setRange(0, sublistLength, _list, start);
return result;