Fix all strong-mode warnings.
R=floitsch@google.com
Review URL: https://codereview.chromium.org//1949753005 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index edfc03d..ac7eb0b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.1.3
+
+* Fix all strong-mode warnings.
+
## 1.1.2
* Fix a bug where `TypedDataBuffer.insertAll` could fail to insert some elements
diff --git a/lib/typed_buffers.dart b/lib/typed_buffers.dart
index 2d1ca13..ac178b5 100644
--- a/lib/typed_buffers.dart
+++ b/lib/typed_buffers.dart
@@ -19,14 +19,21 @@
abstract class _TypedDataBuffer<E> extends ListBase<E> {
static const int INITIAL_LENGTH = 8;
- /// This is a Uint8List for Uint8Buffer. It's both a List<E> and a TypedData,
- /// which we don't have a type for here.
- var _buffer;
+ /// The underlying data buffer.
+ ///
+ /// This is always both a List<E> and a TypedData, which we don't have a type
+ /// for here. For example, for a `Uint8Buffer`, this is a `Uint8List`.
+ List<E> _buffer;
+
+ /// Returns a view of [_buffer] as a [TypedData].
+ TypedData get _typedBuffer => _buffer as TypedData;
+
/// The length of the list being built.
int _length;
_TypedDataBuffer(List<E> buffer)
- : this._buffer = buffer, this._length = buffer.length;
+ : this._buffer = buffer,
+ this._length = buffer.length;
int get length => _length;
E operator[](int index) {
@@ -154,7 +161,7 @@
}
// Reverses the range [start..end) of buffer.
- static void _reverse(List<int> buffer, int start, int end) {
+ static void _reverse(List buffer, int start, int end) {
end--; // Point to last element, not after last element.
while (start < end) {
var first = buffer[start];
@@ -279,11 +286,11 @@
// TypedData.
- int get elementSizeInBytes => _buffer.elementSizeInBytes;
+ int get elementSizeInBytes => _typedBuffer.elementSizeInBytes;
- int get lengthInBytes => _length * _buffer.elementSizeInBytes;
+ int get lengthInBytes => _length * _typedBuffer.elementSizeInBytes;
- int get offsetInBytes => _buffer.offsetInBytes;
+ int get offsetInBytes => _typedBuffer.offsetInBytes;
/// Returns the underlying [ByteBuffer].
///
@@ -291,7 +298,7 @@
/// of this list.
///
/// The buffer may be larger than [lengthInBytes] bytes, but never smaller.
- ByteBuffer get buffer => _buffer.buffer;
+ ByteBuffer get buffer => _typedBuffer.buffer;
// Specialization for the specific type.
@@ -304,12 +311,14 @@
}
abstract class _IntBuffer extends _TypedDataBuffer<int> {
- _IntBuffer(buffer): super(buffer);
+ _IntBuffer(List<int> buffer): super(buffer);
+
int get _defaultValue => 0;
}
abstract class _FloatBuffer extends _TypedDataBuffer<double> {
- _FloatBuffer(buffer): super(buffer);
+ _FloatBuffer(List<double> buffer): super(buffer);
+
double get _defaultValue => 0.0;
}
diff --git a/pubspec.yaml b/pubspec.yaml
index a58a7e7..89d680f 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: typed_data
-version: 1.1.2
+version: 1.1.3
author: Dart Team <misc@dartlang.org>
description: Utility functions and classes related to the 'dart:typed_data' library.
homepage: https://github.com/dart-lang/typed_data
diff --git a/test/typed_buffers_test.dart b/test/typed_buffers_test.dart
index 9e97592..6766816 100644
--- a/test/typed_buffers_test.dart
+++ b/test/typed_buffers_test.dart
@@ -152,13 +152,13 @@
typedef int Rounder(int value);
-Rounder roundUint(bits) {
+Rounder uintRounder(bits) {
int halfbits = (1 << (bits ~/ 2)) - 1;
int mask = halfbits | (halfbits << (bits ~/ 2));
return (int x) => x & mask;
}
-Rounder roundInt(bits) {
+Rounder intRounder(bits) {
int highBit = 1 << (bits - 1);
int mask = highBit - 1;
return (int x) => (x & mask) - (x & highBit);
@@ -166,20 +166,20 @@
int clampUint8(x) => x < 0 ? 0 : x > 255 ? 255 : x;
-void testUint(int bits, var buffer, {String testOn}) {
+void testUint(int bits, buffer(int length), {String testOn}) {
int min = 0;
- Function round = roundUint(bits);
- int max = round(-1);
+ var rounder = uintRounder(bits);
+ int max = rounder(-1);
test("Uint${bits}Buffer", () {
- testIntBuffer(bits, min, max, buffer, round);
+ testIntBuffer(bits, min, max, buffer, rounder);
}, testOn: testOn);
}
-void testInt(int bits, var buffer, {String testOn}) {
+void testInt(int bits, buffer(int length), {String testOn}) {
int min = -(1 << (bits - 1));
int max = -(min + 1);
test("Int${bits}Buffer", () {
- testIntBuffer(bits, min, max, buffer, roundInt(bits));
+ testIntBuffer(bits, min, max, buffer, intRounder(bits));
}, testOn: testOn);
}
@@ -231,7 +231,7 @@
assert(round(max) == max);
// All int buffers default to the value 0.
var buffer = create(0);
- List<int> list = buffer; // Check the type.
+ expect(buffer, new isInstanceOf<List<int>>());
expect(buffer.length, equals(0));
var bytes = bits ~/ 8;
@@ -338,7 +338,7 @@
testFloatBuffer(int bitSize, List samples, create(), double round(double v)) {
test("Float${bitSize}Buffer", () {
var buffer = create();
- List<double> list = buffer; // Test type.
+ expect(buffer, new isInstanceOf<List<double>>());
int byteSize = bitSize ~/ 8;
expect(buffer.length, equals(0));
@@ -393,7 +393,7 @@
}
testFloat32x4Buffer(List floatSamples) {
- List float4Samples = [];
+ var float4Samples = <Float32x4>[];
for (int i = 0; i < floatSamples.length - 3; i++) {
float4Samples.add(new Float32x4(floatSamples[i],
floatSamples[i + 1],
@@ -418,7 +418,7 @@
test("Float32x4Buffer", () {
var buffer = new Float32x4Buffer(5);
- List<Float32x4> list = buffer;
+ expect(buffer, new isInstanceOf<List<Float32x4>>());
expect(buffer.length, equals(5));
expect(buffer.elementSizeInBytes, equals(128 ~/ 8));
@@ -458,15 +458,14 @@
});
}
-void testInt32x4Buffer(intSamples) {
+void testInt32x4Buffer(List<int> intSamples) {
test("Int32x4Buffer", () {
- Function round = roundInt(32);
- int bits = 128;
+ Function rounder = intRounder(32);
int bytes = 128 ~/ 8;
Matcher equals32x4(Int32x4 expected) => new MatchesInt32x4(expected);
var buffer = new Int32x4Buffer(0);
- List<Int32x4> list = buffer; // It's a List.
+ expect(buffer, new isInstanceOf<List<Int32x4>>());
expect(buffer.length, equals(0));
expect(buffer.elementSizeInBytes, equals(bytes));
@@ -486,7 +485,7 @@
expect(buffer.length, equals(0));
var samples = intSamples
- .where((value) => value == round(value)) // Issue 15130
+ .where((value) => value == rounder(value)) // Issue 15130
.map((value) => new Int32x4(value, -value, ~value, ~-value))
.toList();
for (Int32x4 value in samples) {