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

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

Issue 10878077: Unify list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add issue number to TODO. 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
« no previous file with comments | « lib/compiler/implementation/lib/mockimpl.dart ('k') | runtime/lib/array_patch.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 class ListFactory<E> {
6
7 factory List.from(Iterable<E> other) {
8 GrowableObjectArray<E> list = new GrowableObjectArray<E>();
9 for (final e in other) {
10 list.add(e);
11 }
12 return list;
13 }
14
15 factory List([int length = null]) {
16 if (length === null) {
17 return new GrowableObjectArray<E>();
18 } else {
19 return new ObjectArray<E>(length);
20 }
21 }
22 }
23 5
24 // TODO(srdjan): Use shared array implementation. 6 // TODO(srdjan): Use shared array implementation.
25 class ObjectArray<E> implements List<E> { 7 class ObjectArray<E> implements List<E> {
26 8
27 factory ObjectArray(int length) native "ObjectArray_allocate"; 9 factory ObjectArray(int length) native "ObjectArray_allocate";
28 10
29 E operator [](int index) native "ObjectArray_getIndexed"; 11 E operator [](int index) native "ObjectArray_getIndexed";
30 12
31 void operator []=(int index, E value) native "ObjectArray_setIndexed"; 13 void operator []=(int index, E value) native "ObjectArray_setIndexed";
32 14
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (!hasNext()) { 300 if (!hasNext()) {
319 throw const NoMoreElementsException(); 301 throw const NoMoreElementsException();
320 } 302 }
321 return _array[_pos++]; 303 return _array[_pos++];
322 } 304 }
323 305
324 final List<E> _array; 306 final List<E> _array;
325 final int _length; // Cache array length for faster access. 307 final int _length; // Cache array length for faster access.
326 int _pos; 308 int _pos;
327 } 309 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/lib/mockimpl.dart ('k') | runtime/lib/array_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698