88/// They use an underlying buffer, and when that buffer becomes too small, it
99/// is replaced by a new buffer.
1010///
11- /// That means that using the [TypedDataView. buffer] getter is not guaranteed
11+ /// That means that using the ` buffer` getter is not guaranteed
1212/// to return the same result each time it is used, and that the buffer may
1313/// be larger than what the list is using.
1414library typed_data.typed_buffers;
@@ -17,7 +17,7 @@ import "dart:collection" show ListBase;
1717import "dart:typed_data" ;
1818
1919abstract class _TypedDataBuffer <E > extends ListBase <E > {
20- static const int INITIAL_LENGTH = 8 ;
20+ static const int _initialLength = 8 ;
2121
2222 /// The underlying data buffer.
2323 ///
@@ -32,29 +32,30 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
3232 int _length;
3333
3434 _TypedDataBuffer (List <E > buffer)
35- : this . _buffer = buffer,
36- this . _length = buffer.length;
35+ : _buffer = buffer,
36+ _length = buffer.length;
3737
3838 int get length => _length;
39+
3940 E operator [](int index) {
40- if (index >= length) throw new RangeError .index (index, this );
41+ if (index >= length) throw RangeError .index (index, this );
4142 return _buffer[index];
4243 }
4344
4445 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 );
4647 _buffer[index] = value;
4748 }
4849
49- void set length (int newLength) {
50+ set length (int newLength) {
5051 if (newLength < _length) {
5152 E defaultValue = _defaultValue;
5253 for (int i = newLength; i < _length; i++ ) {
5354 _buffer[i] = defaultValue;
5455 }
5556 } else if (newLength > _buffer.length) {
5657 List <E > newBuffer;
57- if (_buffer.length == 0 ) {
58+ if (_buffer.isEmpty ) {
5859 newBuffer = _createBuffer (newLength);
5960 } else {
6061 newBuffer = _createBiggerBuffer (newLength);
@@ -89,7 +90,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
8990 void addAll (Iterable <E > values, [int start = 0 , int end]) {
9091 RangeError .checkNotNegative (start, "start" );
9192 if (end != null && start > end) {
92- throw new RangeError .range (end, start, null , "end" );
93+ throw RangeError .range (end, start, null , "end" );
9394 }
9495
9596 _addAll (values, start, end);
@@ -109,7 +110,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
109110 RangeError .checkNotNegative (start, "start" );
110111 if (end != null ) {
111112 if (start > end) {
112- throw new RangeError .range (end, start, null , "end" );
113+ throw RangeError .range (end, start, null , "end" );
113114 }
114115 if (start == end) return ;
115116 }
@@ -147,10 +148,10 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
147148 }
148149
149150 if (skipCount > 0 ) {
150- throw new StateError ("Too few elements" );
151+ throw StateError ("Too few elements" );
151152 }
152153 if (end != null && writeIndex < end) {
153- throw new RangeError .range (end, start, writeIndex, "end" );
154+ throw RangeError .range (end, start, writeIndex, "end" );
154155 }
155156
156157 // Swap [index.._length) and [_length..writeIndex) by double-reversing.
@@ -196,15 +197,15 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
196197 if (i >= start) add (value);
197198 i++ ;
198199 }
199- if (i < start) throw new StateError ("Too few elements" );
200+ if (i < start) throw StateError ("Too few elements" );
200201 }
201202
202203 /// Like [insertAll] , but with a guaranteed non-`null` [start] and [end] .
203204 void _insertKnownLength (int index, Iterable <E > values, int start, int end) {
204205 if (values is List ) {
205206 end ?? = values.length;
206207 if (start > values.length || end > values.length) {
207- throw new StateError ("Too few elements" );
208+ throw StateError ("Too few elements" );
208209 }
209210 } else {
210211 assert (end != null );
@@ -222,7 +223,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
222223
223224 void insert (int index, E element) {
224225 if (index < 0 || index > _length) {
225- throw new RangeError .range (index, 0 , _length);
226+ throw RangeError .range (index, 0 , _length);
226227 }
227228 if (_length < _buffer.length) {
228229 _buffer.setRange (index + 1 , _length + 1 , _buffer, index);
@@ -258,8 +259,8 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
258259 int newLength = _buffer.length * 2 ;
259260 if (requiredCapacity != null && newLength < requiredCapacity) {
260261 newLength = requiredCapacity;
261- } else if (newLength < INITIAL_LENGTH ) {
262- newLength = INITIAL_LENGTH ;
262+ } else if (newLength < _initialLength ) {
263+ newLength = _initialLength ;
263264 }
264265 return _createBuffer (newLength);
265266 }
@@ -272,7 +273,7 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
272273 }
273274
274275 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);
276277 _setRange (start, end, source, skipCount);
277278 }
278279
@@ -324,74 +325,87 @@ abstract class _FloatBuffer extends _TypedDataBuffer<double> {
324325}
325326
326327class 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);
329331}
330332
331333class 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);
334337}
335338
336339class Uint8ClampedBuffer extends _IntBuffer {
337340 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);
340344}
341345
342346class 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);
345350}
346351
347352class 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);
350356}
351357
352358class 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);
355362}
356363
357364class 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);
360368}
361369
362370class 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);
365374}
366375
367376class 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);
370380}
371381
372382class 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);
376386}
377387
378388class 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);
382392}
383393
384394class 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+
388399 Int32x4 get _defaultValue => _zero;
389- Int32x4List _createBuffer (int size) => new Int32x4List (size);
400+
401+ Int32x4List _createBuffer (int size) => Int32x4List (size);
390402}
391403
392404class Float32x4Buffer extends _TypedDataBuffer <Float32x4 > {
393405 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);
397411}
0 commit comments