Skip to content

Commit 808ca6e

Browse files
authored
Require Dart 3.5, use TypeDataList in many places (dart-archive/typed_data#92)
Tighten types, remove casts, etc
1 parent 4ac0456 commit 808ca6e

File tree

5 files changed

+27
-33
lines changed

5 files changed

+27
-33
lines changed

pkgs/typed_data/.github/workflows/test-package.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
matrix:
4848
# Add macos-latest and/or windows-latest if relevant for this package.
4949
os: [ubuntu-latest]
50-
sdk: [3.1, dev]
50+
sdk: [3.5, dev]
5151
steps:
5252
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
5353
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
@@ -64,5 +64,4 @@ jobs:
6464
if: always() && steps.install.outcome == 'success'
6565
- name: Run Chrome tests - wasm
6666
run: dart test --platform chrome --compiler dart2wasm
67-
# TODO: drop `dev` filter when dart2wasm is working on stable
68-
if: always() && steps.install.outcome == 'success' && matrix.sdk == 'dev'
67+
if: always() && steps.install.outcome == 'success'

pkgs/typed_data/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
## 1.3.3-wip
1+
## 1.4.0-wip
22

3-
* Require Dart 3.1
3+
* The type of the `buffer` constructor argument to `TypedDataBuffer` is now
4+
`TypeDataList<E>` (instead of `List<E>`). While this is breaking change
5+
statically there was a runtime cast that makes this change a no-op in
6+
practice.
7+
* Require Dart 3.5
48

59
## 1.3.2
610

pkgs/typed_data/lib/src/typed_buffer.dart

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ abstract class TypedDataBuffer<E> extends ListBase<E> {
99
static const int _initialLength = 8;
1010

1111
/// The underlying data buffer.
12-
///
13-
/// This is always both a List<E> and a TypedData, which we don't have a type
14-
/// for here. For example, for a `Uint8Buffer`, this is a `Uint8List`.
15-
List<E> _buffer;
16-
17-
/// Returns a view of [_buffer] as a [TypedData].
18-
TypedData get _typedBuffer => _buffer as TypedData;
12+
TypedDataList<E> _buffer;
1913

2014
/// The length of the list being built.
2115
int _length;
2216

23-
TypedDataBuffer(List<E> buffer)
17+
TypedDataBuffer(TypedDataList<E> buffer)
2418
: _buffer = buffer,
2519
_length = buffer.length;
2620

@@ -47,7 +41,7 @@ abstract class TypedDataBuffer<E> extends ListBase<E> {
4741
_buffer[i] = defaultValue;
4842
}
4943
} else if (newLength > _buffer.length) {
50-
List<E> newBuffer;
44+
TypedDataList<E> newBuffer;
5145
if (_buffer.isEmpty) {
5246
newBuffer = _createBuffer(newLength);
5347
} else {
@@ -249,7 +243,7 @@ abstract class TypedDataBuffer<E> extends ListBase<E> {
249243
/// be. If [requiredCapacity] is not null, it will be at least that
250244
/// size. It will always have at least have double the capacity of
251245
/// the current buffer.
252-
List<E> _createBiggerBuffer(int? requiredCapacity) {
246+
TypedDataList<E> _createBiggerBuffer(int? requiredCapacity) {
253247
var newLength = _buffer.length * 2;
254248
if (requiredCapacity != null && newLength < requiredCapacity) {
255249
newLength = requiredCapacity;
@@ -283,19 +277,19 @@ abstract class TypedDataBuffer<E> extends ListBase<E> {
283277

284278
// TypedData.
285279

286-
int get elementSizeInBytes => _typedBuffer.elementSizeInBytes;
280+
int get elementSizeInBytes => _buffer.elementSizeInBytes;
287281

288-
int get lengthInBytes => _length * _typedBuffer.elementSizeInBytes;
282+
int get lengthInBytes => _length * _buffer.elementSizeInBytes;
289283

290-
int get offsetInBytes => _typedBuffer.offsetInBytes;
284+
int get offsetInBytes => _buffer.offsetInBytes;
291285

292286
/// Returns the underlying [ByteBuffer].
293287
///
294288
/// The returned buffer may be replaced by operations that change the [length]
295289
/// of this list.
296290
///
297291
/// The buffer may be larger than [lengthInBytes] bytes, but never smaller.
298-
ByteBuffer get buffer => _typedBuffer.buffer;
292+
ByteBuffer get buffer => _buffer.buffer;
299293

300294
// Specialization for the specific type.
301295

@@ -304,7 +298,7 @@ abstract class TypedDataBuffer<E> extends ListBase<E> {
304298
E get _defaultValue;
305299

306300
// Create a new typed list to use as buffer.
307-
List<E> _createBuffer(int size);
301+
TypedDataList<E> _createBuffer(int size);
308302
}
309303

310304
abstract class _IntBuffer extends TypedDataBuffer<int> {

pkgs/typed_data/lib/src/typed_queue.dart

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,16 @@ import 'package:collection/collection.dart';
1010
import 'typed_buffer.dart';
1111

1212
/// The shared superclass of all the typed queue subclasses.
13-
abstract class _TypedQueue<E, L extends List<E>> with ListMixin<E> {
13+
abstract class _TypedQueue<E, L extends TypedDataList<E>> with ListMixin<E> {
1414
/// The underlying data buffer.
15-
///
16-
/// This is always both a List<E> and a TypedData, which we don't have a type
17-
/// for that. For example, for a `Uint8Queue`, this is a `Uint8List`.
18-
L _table;
15+
TypedDataList<E> _table;
1916

2017
int _head;
2118
int _tail;
2219

2320
/// Create an empty queue.
24-
_TypedQueue(List<E> table)
25-
: _table = table as L,
26-
_head = 0,
21+
_TypedQueue(this._table)
22+
: _head = 0,
2723
_tail = 0;
2824

2925
// Iterable interface.
@@ -330,20 +326,21 @@ abstract class _TypedQueue<E, L extends List<E>> with ListMixin<E> {
330326
L _createList(int size);
331327

332328
// Create a new typed buffer of the given type.
333-
List<E> _createBuffer(int size);
329+
TypedDataBuffer<E> _createBuffer(int size);
334330

335331
/// The default value used to fill the queue when changing length.
336332
E get _defaultValue;
337333
}
338334

339-
abstract class _IntQueue<L extends List<int>> extends _TypedQueue<int, L> {
335+
abstract class _IntQueue<L extends TypedDataList<int>>
336+
extends _TypedQueue<int, L> {
340337
_IntQueue(super.queue);
341338

342339
@override
343340
int get _defaultValue => 0;
344341
}
345342

346-
abstract class _FloatQueue<L extends List<double>>
343+
abstract class _FloatQueue<L extends TypedDataList<double>>
347344
extends _TypedQueue<double, L> {
348345
_FloatQueue(super.queue);
349346

pkgs/typed_data/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: typed_data
2-
version: 1.3.3-wip
2+
version: 1.4.0-wip
33
description: >-
44
Utility functions and classes related to the dart:typed_data library.
55
repository: https://github.com/dart-lang/typed_data
@@ -8,7 +8,7 @@ topics:
88
- data-structures
99

1010
environment:
11-
sdk: ^3.1.0
11+
sdk: ^3.5.0
1212

1313
dependencies:
1414
collection: ^1.15.0

0 commit comments

Comments
 (0)