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

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

Issue 13863012: Refactor List.setRange function. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/html/html_common/filtered_element_list.dart ('k') | sdk/lib/io/file_impl.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 * Utility class that holds a number of byte buffers and can deliver 8 * Utility class that holds a number of byte buffers and can deliver
9 * the bytes either one by one or in chunks. 9 * the bytes either one by one or in chunks.
10 */ 10 */
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 _buffers.removeFirst(); 87 _buffers.removeFirst();
88 _index = 0; 88 _index = 0;
89 } 89 }
90 return result; 90 return result;
91 } else { 91 } else {
92 result = new Uint8List(count); 92 result = new Uint8List(count);
93 int remaining = count; 93 int remaining = count;
94 while (remaining > 0) { 94 while (remaining > 0) {
95 int bytesInFirst = _buffers.first.length - _index; 95 int bytesInFirst = _buffers.first.length - _index;
96 if (bytesInFirst <= remaining) { 96 if (bytesInFirst <= remaining) {
97 result.setRange(count - remaining, 97 int startIndex = count - remaining;
98 bytesInFirst, 98 int endIndex = startIndex + bytesInFirst;
99 _buffers.first, 99 result.setRange(startIndex, endIndex, _buffers.first, _index);
100 _index);
101 _buffers.removeFirst(); 100 _buffers.removeFirst();
102 _index = 0; 101 _index = 0;
103 _length -= bytesInFirst; 102 _length -= bytesInFirst;
104 remaining -= bytesInFirst; 103 remaining -= bytesInFirst;
105 } else { 104 } else {
106 result.setRange(count - remaining, 105 result.setRange(count - remaining, count, _buffers.first, _index);
107 remaining,
108 _buffers.first,
109 _index);
110 _index = remaining; 106 _index = remaining;
111 _length -= remaining; 107 _length -= remaining;
112 remaining = 0; 108 remaining = 0;
113 assert(_index < _buffers.first.length); 109 assert(_index < _buffers.first.length);
114 } 110 }
115 } 111 }
116 return result; 112 return result;
117 } 113 }
118 } 114 }
119 } 115 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 void clear() { 148 void clear() {
153 _index = 0; 149 _index = 0;
154 _length = 0; 150 _length = 0;
155 _buffers = new Queue(); 151 _buffers = new Queue();
156 } 152 }
157 153
158 int _length; // Total number of bytes remaining in the buffers. 154 int _length; // Total number of bytes remaining in the buffers.
159 Queue<List<int>> _buffers; // List of data buffers. 155 Queue<List<int>> _buffers; // List of data buffers.
160 int _index; // Index of the next byte in the first buffer. 156 int _index; // Index of the next byte in the first buffer.
161 } 157 }
OLDNEW
« no previous file with comments | « sdk/lib/html/html_common/filtered_element_list.dart ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698