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

Side by Side Diff: sdk/lib/io/bytes_builder.dart

Issue 2100103002: Fix bug in BytesBuilder. Add tests. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/standalone/io/bytes_builder_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of dart.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * Builds a list of bytes, allowing bytes and lists of bytes to be added at the 8 * Builds a list of bytes, allowing bytes and lists of bytes to be added at the
9 * end. 9 * end.
10 * 10 *
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 153
154 class _BytesBuilder implements BytesBuilder { 154 class _BytesBuilder implements BytesBuilder {
155 int _length = 0; 155 int _length = 0;
156 final List<Uint8List> _chunks = []; 156 final List<Uint8List> _chunks = [];
157 157
158 void add(List<int> bytes) { 158 void add(List<int> bytes) {
159 Uint8List typedBytes; 159 Uint8List typedBytes;
160 if (bytes is Uint8List) { 160 if (bytes is Uint8List) {
161 typedBytes = bytes; 161 typedBytes = bytes;
162 } else { 162 } else {
163 bytes = new Uint8List.fromList(bytes); 163 typedBytes = new Uint8List.fromList(bytes);
164 } 164 }
165 _chunks.add(typedBytes); 165 _chunks.add(typedBytes);
166 _length += typedBytes.length; 166 _length += typedBytes.length;
167 } 167 }
168 168
169 void addByte(int byte) { add([byte]); } 169 void addByte(int byte) { add([byte]); }
170 170
171 List<int> takeBytes() { 171 List<int> takeBytes() {
172 if (_chunks.length == 0) return new Uint8List(0); 172 if (_chunks.length == 0) return new Uint8List(0);
173 if (_chunks.length == 1) { 173 if (_chunks.length == 1) {
(...skipping 26 matching lines...) Expand all
200 200
201 bool get isEmpty => _length == 0; 201 bool get isEmpty => _length == 0;
202 202
203 bool get isNotEmpty => _length != 0; 203 bool get isNotEmpty => _length != 0;
204 204
205 void clear() { 205 void clear() {
206 _length = 0; 206 _length = 0;
207 _chunks.clear(); 207 _chunks.clear();
208 } 208 }
209 } 209 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/bytes_builder_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698