Skip to content

Commit 52440c8

Browse files
committed
Fix all strong-mode warnings.
[email protected] Review URL: https://codereview.chromium.org//1949753005 .
1 parent 4f952fb commit 52440c8

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.1.3
2+
3+
* Fix all strong-mode warnings.
4+
15
## 1.1.2
26

37
* Fix a bug where `TypedDataBuffer.insertAll` could fail to insert some elements

lib/typed_buffers.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ import "dart:typed_data";
1919
abstract class _TypedDataBuffer<E> extends ListBase<E> {
2020
static const int INITIAL_LENGTH = 8;
2121

22-
/// This is a Uint8List for Uint8Buffer. It's both a List<E> and a TypedData,
23-
/// which we don't have a type for here.
24-
var _buffer;
22+
/// The underlying data buffer.
23+
///
24+
/// This is always both a List<E> and a TypedData, which we don't have a type
25+
/// for here. For example, for a `Uint8Buffer`, this is a `Uint8List`.
26+
List<E> _buffer;
27+
28+
/// Returns a view of [_buffer] as a [TypedData].
29+
TypedData get _typedBuffer => _buffer as TypedData;
30+
2531
/// The length of the list being built.
2632
int _length;
2733

2834
_TypedDataBuffer(List<E> buffer)
29-
: this._buffer = buffer, this._length = buffer.length;
35+
: this._buffer = buffer,
36+
this._length = buffer.length;
3037

3138
int get length => _length;
3239
E operator[](int index) {
@@ -154,7 +161,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
154161
}
155162

156163
// Reverses the range [start..end) of buffer.
157-
static void _reverse(List<int> buffer, int start, int end) {
164+
static void _reverse(List buffer, int start, int end) {
158165
end--; // Point to last element, not after last element.
159166
while (start < end) {
160167
var first = buffer[start];
@@ -279,19 +286,19 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
279286

280287
// TypedData.
281288

282-
int get elementSizeInBytes => _buffer.elementSizeInBytes;
289+
int get elementSizeInBytes => _typedBuffer.elementSizeInBytes;
283290

284-
int get lengthInBytes => _length * _buffer.elementSizeInBytes;
291+
int get lengthInBytes => _length * _typedBuffer.elementSizeInBytes;
285292

286-
int get offsetInBytes => _buffer.offsetInBytes;
293+
int get offsetInBytes => _typedBuffer.offsetInBytes;
287294

288295
/// Returns the underlying [ByteBuffer].
289296
///
290297
/// The returned buffer may be replaced by operations that change the [length]
291298
/// of this list.
292299
///
293300
/// The buffer may be larger than [lengthInBytes] bytes, but never smaller.
294-
ByteBuffer get buffer => _buffer.buffer;
301+
ByteBuffer get buffer => _typedBuffer.buffer;
295302

296303
// Specialization for the specific type.
297304

@@ -304,12 +311,14 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
304311
}
305312

306313
abstract class _IntBuffer extends _TypedDataBuffer<int> {
307-
_IntBuffer(buffer): super(buffer);
314+
_IntBuffer(List<int> buffer): super(buffer);
315+
308316
int get _defaultValue => 0;
309317
}
310318

311319
abstract class _FloatBuffer extends _TypedDataBuffer<double> {
312-
_FloatBuffer(buffer): super(buffer);
320+
_FloatBuffer(List<double> buffer): super(buffer);
321+
313322
double get _defaultValue => 0.0;
314323
}
315324

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: typed_data
2-
version: 1.1.2
2+
version: 1.1.3
33
author: Dart Team <[email protected]>
44
description: Utility functions and classes related to the 'dart:typed_data' library.
55
homepage: https://github.com/dart-lang/typed_data

test/typed_buffers_test.dart

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,34 +152,34 @@ double roundToFloat(double value) {
152152

153153
typedef int Rounder(int value);
154154

155-
Rounder roundUint(bits) {
155+
Rounder uintRounder(bits) {
156156
int halfbits = (1 << (bits ~/ 2)) - 1;
157157
int mask = halfbits | (halfbits << (bits ~/ 2));
158158
return (int x) => x & mask;
159159
}
160160

161-
Rounder roundInt(bits) {
161+
Rounder intRounder(bits) {
162162
int highBit = 1 << (bits - 1);
163163
int mask = highBit - 1;
164164
return (int x) => (x & mask) - (x & highBit);
165165
}
166166

167167
int clampUint8(x) => x < 0 ? 0 : x > 255 ? 255 : x;
168168

169-
void testUint(int bits, var buffer, {String testOn}) {
169+
void testUint(int bits, buffer(int length), {String testOn}) {
170170
int min = 0;
171-
Function round = roundUint(bits);
172-
int max = round(-1);
171+
var rounder = uintRounder(bits);
172+
int max = rounder(-1);
173173
test("Uint${bits}Buffer", () {
174-
testIntBuffer(bits, min, max, buffer, round);
174+
testIntBuffer(bits, min, max, buffer, rounder);
175175
}, testOn: testOn);
176176
}
177177

178-
void testInt(int bits, var buffer, {String testOn}) {
178+
void testInt(int bits, buffer(int length), {String testOn}) {
179179
int min = -(1 << (bits - 1));
180180
int max = -(min + 1);
181181
test("Int${bits}Buffer", () {
182-
testIntBuffer(bits, min, max, buffer, roundInt(bits));
182+
testIntBuffer(bits, min, max, buffer, intRounder(bits));
183183
}, testOn: testOn);
184184
}
185185

@@ -231,7 +231,7 @@ void testIntBuffer(int bits, int min, int max,
231231
assert(round(max) == max);
232232
// All int buffers default to the value 0.
233233
var buffer = create(0);
234-
List<int> list = buffer; // Check the type.
234+
expect(buffer, new isInstanceOf<List<int>>());
235235
expect(buffer.length, equals(0));
236236
var bytes = bits ~/ 8;
237237

@@ -338,7 +338,7 @@ void doubleEqual(x, y) {
338338
testFloatBuffer(int bitSize, List samples, create(), double round(double v)) {
339339
test("Float${bitSize}Buffer", () {
340340
var buffer = create();
341-
List<double> list = buffer; // Test type.
341+
expect(buffer, new isInstanceOf<List<double>>());
342342
int byteSize = bitSize ~/ 8;
343343

344344
expect(buffer.length, equals(0));
@@ -393,7 +393,7 @@ testFloatBuffer(int bitSize, List samples, create(), double round(double v)) {
393393
}
394394

395395
testFloat32x4Buffer(List floatSamples) {
396-
List float4Samples = [];
396+
var float4Samples = <Float32x4>[];
397397
for (int i = 0; i < floatSamples.length - 3; i++) {
398398
float4Samples.add(new Float32x4(floatSamples[i],
399399
floatSamples[i + 1],
@@ -418,7 +418,7 @@ testFloat32x4Buffer(List floatSamples) {
418418

419419
test("Float32x4Buffer", () {
420420
var buffer = new Float32x4Buffer(5);
421-
List<Float32x4> list = buffer;
421+
expect(buffer, new isInstanceOf<List<Float32x4>>());
422422

423423
expect(buffer.length, equals(5));
424424
expect(buffer.elementSizeInBytes, equals(128 ~/ 8));
@@ -458,15 +458,14 @@ testFloat32x4Buffer(List floatSamples) {
458458
});
459459
}
460460

461-
void testInt32x4Buffer(intSamples) {
461+
void testInt32x4Buffer(List<int> intSamples) {
462462
test("Int32x4Buffer", () {
463-
Function round = roundInt(32);
464-
int bits = 128;
463+
Function rounder = intRounder(32);
465464
int bytes = 128 ~/ 8;
466465
Matcher equals32x4(Int32x4 expected) => new MatchesInt32x4(expected);
467466

468467
var buffer = new Int32x4Buffer(0);
469-
List<Int32x4> list = buffer; // It's a List.
468+
expect(buffer, new isInstanceOf<List<Int32x4>>());
470469
expect(buffer.length, equals(0));
471470

472471
expect(buffer.elementSizeInBytes, equals(bytes));
@@ -486,7 +485,7 @@ void testInt32x4Buffer(intSamples) {
486485
expect(buffer.length, equals(0));
487486

488487
var samples = intSamples
489-
.where((value) => value == round(value)) // Issue 15130
488+
.where((value) => value == rounder(value)) // Issue 15130
490489
.map((value) => new Int32x4(value, -value, ~value, ~-value))
491490
.toList();
492491
for (Int32x4 value in samples) {

0 commit comments

Comments
 (0)