8
8
/// They use an underlying buffer, and when that buffer becomes too small, it
9
9
/// is replaced by a new buffer.
10
10
///
11
- /// That means that using the [TypedDataView. buffer] getter is not guaranteed
11
+ /// That means that using the ` buffer` getter is not guaranteed
12
12
/// to return the same result each time it is used, and that the buffer may
13
13
/// be larger than what the list is using.
14
14
library typed_data.typed_buffers;
@@ -17,7 +17,7 @@ import "dart:collection" show ListBase;
17
17
import "dart:typed_data" ;
18
18
19
19
abstract class _TypedDataBuffer <E > extends ListBase <E > {
20
- static const int INITIAL_LENGTH = 8 ;
20
+ static const int _initialLength = 8 ;
21
21
22
22
/// The underlying data buffer.
23
23
///
@@ -32,29 +32,30 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
32
32
int _length;
33
33
34
34
_TypedDataBuffer (List <E > buffer)
35
- : this . _buffer = buffer,
36
- this . _length = buffer.length;
35
+ : _buffer = buffer,
36
+ _length = buffer.length;
37
37
38
38
int get length => _length;
39
+
39
40
E operator [](int index) {
40
- if (index >= length) throw new RangeError .index (index, this );
41
+ if (index >= length) throw RangeError .index (index, this );
41
42
return _buffer[index];
42
43
}
43
44
44
45
void operator []= (int index, E value) {
45
- if (index >= length) throw new RangeError .index (index, this );
46
+ if (index >= length) throw RangeError .index (index, this );
46
47
_buffer[index] = value;
47
48
}
48
49
49
- void set length (int newLength) {
50
+ set length (int newLength) {
50
51
if (newLength < _length) {
51
52
E defaultValue = _defaultValue;
52
53
for (int i = newLength; i < _length; i++ ) {
53
54
_buffer[i] = defaultValue;
54
55
}
55
56
} else if (newLength > _buffer.length) {
56
57
List <E > newBuffer;
57
- if (_buffer.length == 0 ) {
58
+ if (_buffer.isEmpty ) {
58
59
newBuffer = _createBuffer (newLength);
59
60
} else {
60
61
newBuffer = _createBiggerBuffer (newLength);
@@ -89,7 +90,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
89
90
void addAll (Iterable <E > values, [int start = 0 , int end]) {
90
91
RangeError .checkNotNegative (start, "start" );
91
92
if (end != null && start > end) {
92
- throw new RangeError .range (end, start, null , "end" );
93
+ throw RangeError .range (end, start, null , "end" );
93
94
}
94
95
95
96
_addAll (values, start, end);
@@ -109,7 +110,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
109
110
RangeError .checkNotNegative (start, "start" );
110
111
if (end != null ) {
111
112
if (start > end) {
112
- throw new RangeError .range (end, start, null , "end" );
113
+ throw RangeError .range (end, start, null , "end" );
113
114
}
114
115
if (start == end) return ;
115
116
}
@@ -147,10 +148,10 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
147
148
}
148
149
149
150
if (skipCount > 0 ) {
150
- throw new StateError ("Too few elements" );
151
+ throw StateError ("Too few elements" );
151
152
}
152
153
if (end != null && writeIndex < end) {
153
- throw new RangeError .range (end, start, writeIndex, "end" );
154
+ throw RangeError .range (end, start, writeIndex, "end" );
154
155
}
155
156
156
157
// Swap [index.._length) and [_length..writeIndex) by double-reversing.
@@ -196,15 +197,15 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
196
197
if (i >= start) add (value);
197
198
i++ ;
198
199
}
199
- if (i < start) throw new StateError ("Too few elements" );
200
+ if (i < start) throw StateError ("Too few elements" );
200
201
}
201
202
202
203
/// Like [insertAll] , but with a guaranteed non-`null` [start] and [end] .
203
204
void _insertKnownLength (int index, Iterable <E > values, int start, int end) {
204
205
if (values is List ) {
205
206
end ?? = values.length;
206
207
if (start > values.length || end > values.length) {
207
- throw new StateError ("Too few elements" );
208
+ throw StateError ("Too few elements" );
208
209
}
209
210
} else {
210
211
assert (end != null );
@@ -222,7 +223,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
222
223
223
224
void insert (int index, E element) {
224
225
if (index < 0 || index > _length) {
225
- throw new RangeError .range (index, 0 , _length);
226
+ throw RangeError .range (index, 0 , _length);
226
227
}
227
228
if (_length < _buffer.length) {
228
229
_buffer.setRange (index + 1 , _length + 1 , _buffer, index);
@@ -258,8 +259,8 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
258
259
int newLength = _buffer.length * 2 ;
259
260
if (requiredCapacity != null && newLength < requiredCapacity) {
260
261
newLength = requiredCapacity;
261
- } else if (newLength < INITIAL_LENGTH ) {
262
- newLength = INITIAL_LENGTH ;
262
+ } else if (newLength < _initialLength ) {
263
+ newLength = _initialLength ;
263
264
}
264
265
return _createBuffer (newLength);
265
266
}
@@ -272,7 +273,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
272
273
}
273
274
274
275
void setRange (int start, int end, Iterable <E > source, [int skipCount = 0 ]) {
275
- if (end > _length) throw new RangeError .range (end, 0 , _length);
276
+ if (end > _length) throw RangeError .range (end, 0 , _length);
276
277
_setRange (start, end, source, skipCount);
277
278
}
278
279
@@ -324,74 +325,87 @@ abstract class _FloatBuffer extends _TypedDataBuffer<double> {
324
325
}
325
326
326
327
class Uint8Buffer extends _IntBuffer {
327
- Uint8Buffer ([int initialLength = 0 ]) : super (new Uint8List (initialLength));
328
- Uint8List _createBuffer (int size) => new Uint8List (size);
328
+ Uint8Buffer ([int initialLength = 0 ]) : super (Uint8List (initialLength));
329
+
330
+ Uint8List _createBuffer (int size) => Uint8List (size);
329
331
}
330
332
331
333
class Int8Buffer extends _IntBuffer {
332
- Int8Buffer ([int initialLength = 0 ]) : super (new Int8List (initialLength));
333
- Int8List _createBuffer (int size) => new Int8List (size);
334
+ Int8Buffer ([int initialLength = 0 ]) : super (Int8List (initialLength));
335
+
336
+ Int8List _createBuffer (int size) => Int8List (size);
334
337
}
335
338
336
339
class Uint8ClampedBuffer extends _IntBuffer {
337
340
Uint8ClampedBuffer ([int initialLength = 0 ])
338
- : super (new Uint8ClampedList (initialLength));
339
- Uint8ClampedList _createBuffer (int size) => new Uint8ClampedList (size);
341
+ : super (Uint8ClampedList (initialLength));
342
+
343
+ Uint8ClampedList _createBuffer (int size) => Uint8ClampedList (size);
340
344
}
341
345
342
346
class Uint16Buffer extends _IntBuffer {
343
- Uint16Buffer ([int initialLength = 0 ]) : super (new Uint16List (initialLength));
344
- Uint16List _createBuffer (int size) => new Uint16List (size);
347
+ Uint16Buffer ([int initialLength = 0 ]) : super (Uint16List (initialLength));
348
+
349
+ Uint16List _createBuffer (int size) => Uint16List (size);
345
350
}
346
351
347
352
class Int16Buffer extends _IntBuffer {
348
- Int16Buffer ([int initialLength = 0 ]) : super (new Int16List (initialLength));
349
- Int16List _createBuffer (int size) => new Int16List (size);
353
+ Int16Buffer ([int initialLength = 0 ]) : super (Int16List (initialLength));
354
+
355
+ Int16List _createBuffer (int size) => Int16List (size);
350
356
}
351
357
352
358
class Uint32Buffer extends _IntBuffer {
353
- Uint32Buffer ([int initialLength = 0 ]) : super (new Uint32List (initialLength));
354
- Uint32List _createBuffer (int size) => new Uint32List (size);
359
+ Uint32Buffer ([int initialLength = 0 ]) : super (Uint32List (initialLength));
360
+
361
+ Uint32List _createBuffer (int size) => Uint32List (size);
355
362
}
356
363
357
364
class Int32Buffer extends _IntBuffer {
358
- Int32Buffer ([int initialLength = 0 ]) : super (new Int32List (initialLength));
359
- Int32List _createBuffer (int size) => new Int32List (size);
365
+ Int32Buffer ([int initialLength = 0 ]) : super (Int32List (initialLength));
366
+
367
+ Int32List _createBuffer (int size) => Int32List (size);
360
368
}
361
369
362
370
class Uint64Buffer extends _IntBuffer {
363
- Uint64Buffer ([int initialLength = 0 ]) : super (new Uint64List (initialLength));
364
- Uint64List _createBuffer (int size) => new Uint64List (size);
371
+ Uint64Buffer ([int initialLength = 0 ]) : super (Uint64List (initialLength));
372
+
373
+ Uint64List _createBuffer (int size) => Uint64List (size);
365
374
}
366
375
367
376
class Int64Buffer extends _IntBuffer {
368
- Int64Buffer ([int initialLength = 0 ]) : super (new Int64List (initialLength));
369
- Int64List _createBuffer (int size) => new Int64List (size);
377
+ Int64Buffer ([int initialLength = 0 ]) : super (Int64List (initialLength));
378
+
379
+ Int64List _createBuffer (int size) => Int64List (size);
370
380
}
371
381
372
382
class Float32Buffer extends _FloatBuffer {
373
- Float32Buffer ([int initialLength = 0 ])
374
- : super ( new Float32List (initialLength));
375
- Float32List _createBuffer (int size) => new Float32List (size);
383
+ Float32Buffer ([int initialLength = 0 ]) : super ( Float32List (initialLength));
384
+
385
+ Float32List _createBuffer (int size) => Float32List (size);
376
386
}
377
387
378
388
class Float64Buffer extends _FloatBuffer {
379
- Float64Buffer ([int initialLength = 0 ])
380
- : super ( new Float64List (initialLength));
381
- Float64List _createBuffer (int size) => new Float64List (size);
389
+ Float64Buffer ([int initialLength = 0 ]) : super ( Float64List (initialLength));
390
+
391
+ Float64List _createBuffer (int size) => Float64List (size);
382
392
}
383
393
384
394
class Int32x4Buffer extends _TypedDataBuffer <Int32x4 > {
385
- static Int32x4 _zero = new Int32x4 (0 , 0 , 0 , 0 );
386
- Int32x4Buffer ([int initialLength = 0 ])
387
- : super (new Int32x4List (initialLength));
395
+ static final Int32x4 _zero = Int32x4 (0 , 0 , 0 , 0 );
396
+
397
+ Int32x4Buffer ([int initialLength = 0 ]) : super (Int32x4List (initialLength));
398
+
388
399
Int32x4 get _defaultValue => _zero;
389
- Int32x4List _createBuffer (int size) => new Int32x4List (size);
400
+
401
+ Int32x4List _createBuffer (int size) => Int32x4List (size);
390
402
}
391
403
392
404
class Float32x4Buffer extends _TypedDataBuffer <Float32x4 > {
393
405
Float32x4Buffer ([int initialLength = 0 ])
394
- : super (new Float32x4List (initialLength));
395
- Float32x4 get _defaultValue => new Float32x4 .zero ();
396
- Float32x4List _createBuffer (int size) => new Float32x4List (size);
406
+ : super (Float32x4List (initialLength));
407
+
408
+ Float32x4 get _defaultValue => Float32x4 .zero ();
409
+
410
+ Float32x4List _createBuffer (int size) => Float32x4List (size);
397
411
}
0 commit comments