Require Dart 3.5, use TypeDataList in many places (#92)
Tighten types, remove casts, etc
diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml
index 3af713a..a39c2df 100644
--- a/.github/workflows/test-package.yml
+++ b/.github/workflows/test-package.yml
@@ -47,7 +47,7 @@
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
- sdk: [3.1, dev]
+ sdk: [3.5, dev]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
@@ -64,5 +64,4 @@
if: always() && steps.install.outcome == 'success'
- name: Run Chrome tests - wasm
run: dart test --platform chrome --compiler dart2wasm
- # TODO: drop `dev` filter when dart2wasm is working on stable
- if: always() && steps.install.outcome == 'success' && matrix.sdk == 'dev'
+ if: always() && steps.install.outcome == 'success'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2b3af0e..af74b2f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,10 @@
-## 1.3.3-wip
+## 1.4.0-wip
-* Require Dart 3.1
+* The type of the `buffer` constructor argument to `TypedDataBuffer` is now
+ `TypeDataList<E>` (instead of `List<E>`). While this is breaking change
+ statically there was a runtime cast that makes this change a no-op in
+ practice.
+* Require Dart 3.5
## 1.3.2
diff --git a/lib/src/typed_buffer.dart b/lib/src/typed_buffer.dart
index b79e7a6..dcb2c58 100644
--- a/lib/src/typed_buffer.dart
+++ b/lib/src/typed_buffer.dart
@@ -9,18 +9,12 @@
static const int _initialLength = 8;
/// 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;
+ TypedDataList<E> _buffer;
/// The length of the list being built.
int _length;
- TypedDataBuffer(List<E> buffer)
+ TypedDataBuffer(TypedDataList<E> buffer)
: _buffer = buffer,
_length = buffer.length;
@@ -47,7 +41,7 @@
_buffer[i] = defaultValue;
}
} else if (newLength > _buffer.length) {
- List<E> newBuffer;
+ TypedDataList<E> newBuffer;
if (_buffer.isEmpty) {
newBuffer = _createBuffer(newLength);
} else {
@@ -249,7 +243,7 @@
/// be. If [requiredCapacity] is not null, it will be at least that
/// size. It will always have at least have double the capacity of
/// the current buffer.
- List<E> _createBiggerBuffer(int? requiredCapacity) {
+ TypedDataList<E> _createBiggerBuffer(int? requiredCapacity) {
var newLength = _buffer.length * 2;
if (requiredCapacity != null && newLength < requiredCapacity) {
newLength = requiredCapacity;
@@ -283,11 +277,11 @@
// TypedData.
- int get elementSizeInBytes => _typedBuffer.elementSizeInBytes;
+ int get elementSizeInBytes => _buffer.elementSizeInBytes;
- int get lengthInBytes => _length * _typedBuffer.elementSizeInBytes;
+ int get lengthInBytes => _length * _buffer.elementSizeInBytes;
- int get offsetInBytes => _typedBuffer.offsetInBytes;
+ int get offsetInBytes => _buffer.offsetInBytes;
/// Returns the underlying [ByteBuffer].
///
@@ -295,7 +289,7 @@
/// of this list.
///
/// The buffer may be larger than [lengthInBytes] bytes, but never smaller.
- ByteBuffer get buffer => _typedBuffer.buffer;
+ ByteBuffer get buffer => _buffer.buffer;
// Specialization for the specific type.
@@ -304,7 +298,7 @@
E get _defaultValue;
// Create a new typed list to use as buffer.
- List<E> _createBuffer(int size);
+ TypedDataList<E> _createBuffer(int size);
}
abstract class _IntBuffer extends TypedDataBuffer<int> {
diff --git a/lib/src/typed_queue.dart b/lib/src/typed_queue.dart
index c792917..84ce529 100644
--- a/lib/src/typed_queue.dart
+++ b/lib/src/typed_queue.dart
@@ -10,20 +10,16 @@
import 'typed_buffer.dart';
/// The shared superclass of all the typed queue subclasses.
-abstract class _TypedQueue<E, L extends List<E>> with ListMixin<E> {
+abstract class _TypedQueue<E, L extends TypedDataList<E>> with ListMixin<E> {
/// The underlying data buffer.
- ///
- /// This is always both a List<E> and a TypedData, which we don't have a type
- /// for that. For example, for a `Uint8Queue`, this is a `Uint8List`.
- L _table;
+ TypedDataList<E> _table;
int _head;
int _tail;
/// Create an empty queue.
- _TypedQueue(List<E> table)
- : _table = table as L,
- _head = 0,
+ _TypedQueue(this._table)
+ : _head = 0,
_tail = 0;
// Iterable interface.
@@ -330,20 +326,21 @@
L _createList(int size);
// Create a new typed buffer of the given type.
- List<E> _createBuffer(int size);
+ TypedDataBuffer<E> _createBuffer(int size);
/// The default value used to fill the queue when changing length.
E get _defaultValue;
}
-abstract class _IntQueue<L extends List<int>> extends _TypedQueue<int, L> {
+abstract class _IntQueue<L extends TypedDataList<int>>
+ extends _TypedQueue<int, L> {
_IntQueue(super.queue);
@override
int get _defaultValue => 0;
}
-abstract class _FloatQueue<L extends List<double>>
+abstract class _FloatQueue<L extends TypedDataList<double>>
extends _TypedQueue<double, L> {
_FloatQueue(super.queue);
diff --git a/pubspec.yaml b/pubspec.yaml
index 8b595d7..8984b2b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: typed_data
-version: 1.3.3-wip
+version: 1.4.0-wip
description: >-
Utility functions and classes related to the dart:typed_data library.
repository: https://github.com/dart-lang/typed_data
@@ -8,7 +8,7 @@
- data-structures
environment:
- sdk: ^3.1.0
+ sdk: ^3.5.0
dependencies:
collection: ^1.15.0