Chromium Code Reviews| Index: lib/typed_buffers.dart |
| diff --git a/lib/typed_buffers.dart b/lib/typed_buffers.dart |
| index 50ed2414c4cbd58d196a720e9706ecf31338a18e..4bb6be73589bf0ccef50a847651821aae664b492 100644 |
| --- a/lib/typed_buffers.dart |
| +++ b/lib/typed_buffers.dart |
| @@ -71,7 +71,32 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> { |
| void add(E value) { _add(value); } |
| void addAll(Iterable<E> values) { |
|
Lasse Reichstein Nielsen
2015/10/14 07:09:59
Maybe addAll is a special case of insertAll, and w
Lasse Reichstein Nielsen
2015/10/14 07:10:00
I'd rather have specialized list code and general
nweiz
2015/10/14 20:20:20
Really? This is contrary to what ListBase does in
nweiz
2015/10/14 20:20:20
Done. ListBase.insertAll bottoms out on setRange a
|
| - for (E value in values) _add(value); |
| + var list = values is List ? values : values.toList(); |
| + var newLength = _length + list.length; |
| + _createBiggerBuffer(newLength); |
|
Lasse Reichstein Nielsen
2015/10/14 07:10:00
Only grow the backing store if necessary.
The _cre
nweiz
2015/10/14 20:20:20
Done.
|
| + _setRange(_length, newLength, list); |
| + _length = newLength; |
| + } |
| + |
| + /// Adds a range of values in [source] to the end of the buffer. |
|
Lasse Reichstein Nielsen
2015/10/14 07:09:59
Comment format is inconsistent with the rest of th
nweiz
2015/10/14 20:20:20
The existing style is already inconsistent—see [_b
|
| + /// |
| + /// This adds values from [sourceStart] (inclusive) to [sourceEnd] |
| + /// (exclusive). If [sourceEnd] is omitted, adds all values after |
| + /// [sourceStart]. |
| + void addRange(Iterable<E> source, int sourceStart, [int sourceEnd]) { |
|
Lasse Reichstein Nielsen
2015/10/14 07:09:59
Validate sourceStart and sourceEnd:
0 <= sourceS
Lasse Reichstein Nielsen
2015/10/14 07:09:59
Just add the parameters to addAll;
void addAll(I
Lasse Reichstein Nielsen
2015/10/14 07:10:00
Naming-wise, functions named "somethingRange" usua
nweiz
2015/10/14 20:20:20
Acknowledged.
nweiz
2015/10/14 20:20:20
Done.
Do you really prefer "start" and "end" to "
nweiz
2015/10/14 20:20:20
Done.
|
| + var list; |
| + if (source is List) { |
| + list = source; |
| + } else { |
| + if (sourceEnd != null) source = source.take(sourceEnd); |
| + list = source.skip(sourceStart).toList(); |
|
Lasse Reichstein Nielsen
2015/10/14 07:10:00
This looks wrong - you create a list of only the e
nweiz
2015/10/14 20:20:20
Done.
|
| + } |
| + |
| + sourceEnd ??= list.length; |
| + var newLength = _length + sourceEnd - sourceStart; |
| + _createBiggerBuffer(newLength); |
| + _setRange(_length, newLength, list, sourceStart); |
| + _length = newLength; |
| } |
| void insert(int index, E element) { |
| @@ -116,6 +141,11 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> { |
| void setRange(int start, int end, Iterable<E> source, [int skipCount = 0]) { |
| if (end > _length) throw new RangeError.range(end, 0, _length); |
| + _setRange(start, end, source._buffer, skipCount); |
| + } |
| + |
| + /// Like [setRange], but with no bounds checking. |
| + void _setRange(int start, int end, Iterable<E> source, [int skipCount = 0]) { |
|
Lasse Reichstein Nielsen
2015/10/14 07:10:00
Make skipCount not optional here.
I generally don
nweiz
2015/10/14 20:20:20
Done.
|
| if (source is _TypedDataBuffer<E>) { |
| _buffer.setRange(start, end, source._buffer, skipCount); |
| } else { |