OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Growable typed-data lists. | 6 * Growable typed-data lists. |
7 * | 7 * |
8 * These lists works just as a typed-data list, except that they are growable. | 8 * These lists works just as a typed-data list, except that they are growable. |
9 * They use an underlying buffer, and when that buffer becomes too small, it | 9 * They use an underlying buffer, and when that buffer becomes too small, it |
10 * is replaced by a new buffer. | 10 * is replaced by a new buffer. |
(...skipping 14 matching lines...) Expand all Loading... |
25 /// which we don't have a type for here. | 25 /// which we don't have a type for here. |
26 var _buffer; | 26 var _buffer; |
27 /// The length of the list being built. | 27 /// The length of the list being built. |
28 int _length; | 28 int _length; |
29 | 29 |
30 _TypedDataBuffer(List<E> buffer) | 30 _TypedDataBuffer(List<E> buffer) |
31 : this._buffer = buffer, this._length = buffer.length; | 31 : this._buffer = buffer, this._length = buffer.length; |
32 | 32 |
33 int get length => _length; | 33 int get length => _length; |
34 E operator[](int index) { | 34 E operator[](int index) { |
35 if (index >= length) throw new RangeError.range(index, 0, length - 1); | 35 if (index >= length) throw new RangeError.index(index, this); |
36 return _buffer[index]; | 36 return _buffer[index]; |
37 } | 37 } |
38 | 38 |
39 void operator[]=(int index, E value) { | 39 void operator[]=(int index, E value) { |
40 if (index >= length) throw new RangeError.range(index, 0, length - 1); | 40 if (index >= length) throw new RangeError.index(index, this); |
41 _buffer[index] = value; | 41 _buffer[index] = value; |
42 } | 42 } |
43 | 43 |
44 void set length(int newLength) { | 44 void set length(int newLength) { |
45 if (newLength < _length) { | 45 if (newLength < _length) { |
46 E defaultValue = _defaultValue; | 46 E defaultValue = _defaultValue; |
47 for (int i = newLength; i < _length; i++) { | 47 for (int i = newLength; i < _length; i++) { |
48 _buffer[i] = defaultValue; | 48 _buffer[i] = defaultValue; |
49 } | 49 } |
50 } else if (newLength > _buffer.length) { | 50 } else if (newLength > _buffer.length) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 Int32x4 get _defaultValue => _zero; | 226 Int32x4 get _defaultValue => _zero; |
227 Int32x4List _createBuffer(int size) => new Int32x4List(size); | 227 Int32x4List _createBuffer(int size) => new Int32x4List(size); |
228 } | 228 } |
229 | 229 |
230 class Float32x4Buffer extends _TypedDataBuffer<Float32x4> { | 230 class Float32x4Buffer extends _TypedDataBuffer<Float32x4> { |
231 Float32x4Buffer([int initialLength = 0]) | 231 Float32x4Buffer([int initialLength = 0]) |
232 : super(new Float32x4List(initialLength)); | 232 : super(new Float32x4List(initialLength)); |
233 Float32x4 get _defaultValue => new Float32x4.zero(); | 233 Float32x4 get _defaultValue => new Float32x4.zero(); |
234 Float32x4List _createBuffer(int size) => new Float32x4List(size); | 234 Float32x4List _createBuffer(int size) => new Float32x4List(size); |
235 } | 235 } |
OLD | NEW |