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

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

Issue 14402013: Revert "- Do not keep growing when creating Lists from Iterables." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | no next file » | 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 // The _GrowableArrayMarker class is used to signal to the List() factory 5 // The _GrowableArrayMarker class is used to signal to the List() factory
6 // whether a parameter was passed. 6 // whether a parameter was passed.
7 class _GrowableArrayMarker implements int { 7 class _GrowableArrayMarker implements int {
8 const _GrowableArrayMarker(); 8 const _GrowableArrayMarker();
9 } 9 }
10 10
(...skipping 14 matching lines...) Expand all
25 // of new _ObjectArray. 25 // of new _ObjectArray.
26 var result = new _ObjectArray<E>(length); 26 var result = new _ObjectArray<E>(length);
27 if (fill != null) { 27 if (fill != null) {
28 for (int i = 0; i < length; i++) { 28 for (int i = 0; i < length; i++) {
29 result[i] = fill; 29 result[i] = fill;
30 } 30 }
31 } 31 }
32 return result; 32 return result;
33 } 33 }
34 34
35 /* patch */ factory List.from(Iterable other, { bool growable: true }) {
36 // TODO(iposva): Avoid the iterators for the known lists and do the copy in
37 // the VM directly.
38 var len = null;
39 // TODO(iposva): Remove this dance once dart2js does not implement
40 // an Iterable that throws on calling length.
41 try {
42 len = other.length;
43 } catch (e) {
44 // Ensure that we try again below.
45 len = null;
46 }
47 if (len == null) {
48 len = 0;
49 try {
50 var iter = other.iterator;
51 while (iter.moveNext()) {
52 len++;
53 }
54 } catch (e) {
55 rethrow; // Giving up and throwing to the caller.
56 }
57 }
58 var result;
59 if (growable) {
60 result = new _GrowableObjectArray<E>.withCapacity(len);
61 result.length = len;
62 } else {
63 result = new _ObjectArray<E>(len);
64 }
65 var iter = other.iterator;
66 for (var i = 0; i < len; i++) {
67 iter.moveNext();
68 result[i] = iter.current;
69 }
70 return result;
71 }
72
73 // Factory constructing a mutable List from a parser generated List literal. 35 // Factory constructing a mutable List from a parser generated List literal.
74 // [elements] contains elements that are already type checked. 36 // [elements] contains elements that are already type checked.
75 factory List._fromLiteral(List elements) { 37 factory List._fromLiteral(List elements) {
76 if (elements.isEmpty) { 38 if (elements.isEmpty) {
77 return new _GrowableObjectArray<E>(0); 39 return new _GrowableObjectArray<E>(0);
78 } 40 }
79 var result = new _GrowableObjectArray<E>.withData(elements); 41 var result = new _GrowableObjectArray<E>.withData(elements);
80 result._setLength(elements.length); 42 result._setLength(elements.length);
81 return result; 43 return result;
82 } 44 }
83 } 45 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698