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

Side by Side Diff: runtime/lib/growable_array.dart

Issue 10905010: Some code cleanups in arrays, fix rangeCheck (issue 2899). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
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 class GrowableObjectArray<T> implements List<T> { 5 class GrowableObjectArray<T> implements List<T> {
6 factory GrowableObjectArray._uninstantiable() { 6 factory GrowableObjectArray._uninstantiable() {
7 throw const UnsupportedOperationException( 7 throw const UnsupportedOperationException(
8 "GrowableObjectArray can only be allocated by the VM"); 8 "GrowableObjectArray can only be allocated by the VM");
9 } 9 }
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 start + length, 46 start + length,
47 old_length - start); 47 old_length - start);
48 for (int i = start; i < start + length; i++) { 48 for (int i = start; i < start + length; i++) {
49 this[i] = initialValue; 49 this[i] = initialValue;
50 } 50 }
51 } 51 }
52 52
53 List<T> getRange(int start, int length) { 53 List<T> getRange(int start, int length) {
54 if (length == 0) return []; 54 if (length == 0) return [];
55 Arrays.rangeCheck(this, start, length); 55 Arrays.rangeCheck(this, start, length);
56 List list = new List<T>(); 56 List list = new GrowableObjectArray<T>.withCapacity(length);
57 list.length = length; 57 list.length = length;
58 Arrays.copy(this, start, list, 0, length); 58 Arrays.copy(this, start, list, 0, length);
59 return list; 59 return list;
60 } 60 }
61 61
62 factory GrowableObjectArray() { 62 factory GrowableObjectArray() {
63 var data = new ObjectArray<T>(4); 63 var data = new ObjectArray<T>(4);
64 return new GrowableObjectArray<T>.fromObjectArray(data); 64 return new GrowableObjectArray<T>.fromObjectArray(data);
65 } 65 }
66 66
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 for (int i = 0; i < length; i++) { 169 for (int i = 0; i < length; i++) {
170 f(this[i]); 170 f(this[i]);
171 } 171 }
172 } 172 }
173 173
174 Collection map(f(T element)) { 174 Collection map(f(T element)) {
175 return Collections.map(this, 175 return Collections.map(this,
176 new GrowableObjectArray.withCapacity(length), f); 176 new GrowableObjectArray.withCapacity(length), f);
177 } 177 }
178 178
179 Dynamic reduce(Dynamic initialValue, 179 reduce(initialValue, combine(previousValue, T element)) {
180 Dynamic combine(Dynamic previousValue, T element)) {
181 return Collections.reduce(this, initialValue, combine); 180 return Collections.reduce(this, initialValue, combine);
182 } 181 }
183 182
184 Collection<T> filter(bool f(T element)) { 183 Collection<T> filter(bool f(T element)) {
185 return Collections.filter(this, new GrowableObjectArray<T>(), f); 184 return Collections.filter(this, new GrowableObjectArray<T>(), f);
186 } 185 }
187 186
188 bool every(bool f(T element)) { 187 bool every(bool f(T element)) {
189 return Collections.every(this, f); 188 return Collections.every(this, f);
190 } 189 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 T next() { 227 T next() {
229 if (!hasNext()) { 228 if (!hasNext()) {
230 throw const NoMoreElementsException(); 229 throw const NoMoreElementsException();
231 } 230 }
232 return _array[_pos++]; 231 return _array[_pos++];
233 } 232 }
234 233
235 final GrowableObjectArray<T> _array; 234 final GrowableObjectArray<T> _array;
236 int _pos; 235 int _pos;
237 } 236 }
OLDNEW
« corelib/src/implementation/arrays.dart ('K') | « runtime/lib/array.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698