Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Unified Diff: lib/typed_buffers.dart

Issue 1728943003: Fix TypedDataBuffer.insertAll() with an Iterable. (Closed) Base URL: git@github.com:dart-lang/typed_data@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/typed_buffers.dart
diff --git a/lib/typed_buffers.dart b/lib/typed_buffers.dart
index c3c0f38a503c3c856775e5b98211293aa5e7d7ce..24dca271af1bb9a834fb200e9d4cfd4becf4777e 100644
--- a/lib/typed_buffers.dart
+++ b/lib/typed_buffers.dart
@@ -125,25 +125,26 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
// Add elements at end, growing as appropriate, then put them back at
// position [index] using flip-by-double-reverse.
- if (end != null) values = values.take(end);
- int writeIndex = _length;
- int skipCount = start;
+ var writeIndex = _length;
+ var skipCount = start;
for (var value in values) {
if (skipCount > 0) {
skipCount--;
continue;
}
if (writeIndex == _buffer.length) {
- _grow();
+ _grow(writeIndex);
}
_buffer[writeIndex++] = value;
}
+
if (skipCount > 0) {
throw new StateError("Too few elements");
}
if (end != null && writeIndex < end) {
throw new RangeError.range(end, start, writeIndex, "end");
}
+
// Swap [index.._length) and [_length..writeIndex) by double-reversing.
_reverse(_buffer, index, _length);
_reverse(_buffer, _length, writeIndex);
@@ -255,8 +256,13 @@ abstract class _TypedDataBuffer<E> extends ListBase<E> {
return _createBuffer(newLength);
}
- void _grow() {
- _buffer = _createBiggerBuffer(null)..setRange(0, _length, _buffer);
+ /// Grows the buffer.
+ ///
+ /// This copies the first [length] elements into the new buffer. It defaults
+ /// to copying [_length] elements.
+ void _grow([int length]) {
Lasse Reichstein Nielsen 2016/02/24 11:06:42 I would generally not make internal functions have
nweiz 2016/02/24 18:45:56 Done.
+ _buffer = _createBiggerBuffer(null)
+ ..setRange(0, length ?? _length, _buffer);
}
void setRange(int start, int end, Iterable<E> source, [int skipCount = 0]) {
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698