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

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

Issue 8339015: Rename GrowableObjectArray to ListImplementation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 2 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 | « no previous file | runtime/lib/growable_array.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // TODO(ngeoffray): Temporary definition until we remove all uses of 'Array'. 5 // TODO(ngeoffray): Temporary definition until we remove all uses of 'Array'.
6 interface Array<T> extends List<T> { 6 interface Array<T> extends List<T> {
7 } 7 }
8 8
9 class ListFactory<T> { 9 class ListFactory<T> {
10 10
11 factory List.from(Iterable<T> other) { 11 factory List.from(Iterable<T> other) {
12 GrowableObjectArray<T> list = new GrowableObjectArray<T>(); 12 List<T> list = new List<T>();
13 for (final e in other) { 13 for (final e in other) {
14 list.add(e); 14 list.add(e);
15 } 15 }
16 return list; 16 return list;
17 } 17 }
18 18
19 factory List.fromList(List<T> other, int startIndex, int endIndex) { 19 factory List.fromList(List<T> other, int startIndex, int endIndex) {
20 List list = new List<T>(); 20 List list = new List<T>();
21 if (endIndex > other.length) endIndex = other.length; 21 if (endIndex > other.length) endIndex = other.length;
22 if (startIndex < 0) startIndex = 0; 22 if (startIndex < 0) startIndex = 0;
23 int count = endIndex - startIndex; 23 int count = endIndex - startIndex;
24 if (count > 0) { 24 if (count > 0) {
25 list.length = count; 25 list.length = count;
26 Arrays.copy(other, startIndex, list, 0, count); 26 Arrays.copy(other, startIndex, list, 0, count);
27 } 27 }
28 return list; 28 return list;
29 } 29 }
30 30
31 factory List([int length = null]) { 31 factory List([int length = null]) {
32 if (length === null) { 32 if (length === null) {
33 return new GrowableObjectArray<T>(); 33 return new ListImplementation<T>();
34 } else { 34 } else {
35 return new ObjectArray<T>(length); 35 return new ObjectArray<T>(length);
36 } 36 }
37 } 37 }
38 } 38 }
39 39
40 // TODO(srdjan): Use shared array implementation. 40 // TODO(srdjan): Use shared array implementation.
41 class ObjectArray<T> implements Array<T> { 41 class ObjectArray<T> implements Array<T> {
42 42
43 factory ObjectArray(int length) native "ObjectArray_allocate"; 43 factory ObjectArray(int length) native "ObjectArray_allocate";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 /** 92 /**
93 * Collection interface. 93 * Collection interface.
94 */ 94 */
95 95
96 void forEach(f(T element)) { 96 void forEach(f(T element)) {
97 Collections.forEach(this, f); 97 Collections.forEach(this, f);
98 } 98 }
99 99
100 Collection<T> filter(bool f(T element)) { 100 Collection<T> filter(bool f(T element)) {
101 return Collections.filter(this, new GrowableObjectArray<T>(), f); 101 return Collections.filter(this, new List<T>(), f);
102 } 102 }
103 103
104 bool every(bool f(T element)) { 104 bool every(bool f(T element)) {
105 return Collections.every(this, f); 105 return Collections.every(this, f);
106 } 106 }
107 107
108 bool some(bool f(T element)) { 108 bool some(bool f(T element)) {
109 return Collections.some(this, f); 109 return Collections.some(this, f);
110 } 110 }
111 111
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 /** 211 /**
212 * Collection interface. 212 * Collection interface.
213 */ 213 */
214 214
215 void forEach(f(T element)) { 215 void forEach(f(T element)) {
216 Collections.forEach(this, f); 216 Collections.forEach(this, f);
217 } 217 }
218 218
219 Collection<T> filter(bool f(T element)) { 219 Collection<T> filter(bool f(T element)) {
220 return Collections.filter(this, new GrowableObjectArray<T>(), f); 220 return Collections.filter(this, new List<T>(), f);
221 } 221 }
222 222
223 bool every(bool f(T element)) { 223 bool every(bool f(T element)) {
224 return Collections.every(this, f); 224 return Collections.every(this, f);
225 } 225 }
226 226
227 bool some(bool f(T element)) { 227 bool some(bool f(T element)) {
228 return Collections.some(this, f); 228 return Collections.some(this, f);
229 } 229 }
230 230
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 if (!hasNext()) { 303 if (!hasNext()) {
304 throw const NoMoreElementsException(); 304 throw const NoMoreElementsException();
305 } 305 }
306 return _array[_pos++]; 306 return _array[_pos++];
307 } 307 }
308 308
309 final Array<T> _array; 309 final Array<T> _array;
310 final int _length; // Cache array length for faster access. 310 final int _length; // Cache array length for faster access.
311 int _pos; 311 int _pos;
312 } 312 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/growable_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698