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

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

Issue 1440663003: Add "growable" parameter to List.filled constructor. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | sdk/lib/_internal/js_runtime/lib/core_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 // 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
11 const _GROWABLE_ARRAY_MARKER = const _GrowableArrayMarker(); 11 const _GROWABLE_ARRAY_MARKER = const _GrowableArrayMarker();
12 12
13 patch class List<E> { 13 patch class List<E> {
14 /* patch */ factory List([int length = _GROWABLE_ARRAY_MARKER]) { 14 /* patch */ factory List([int length = _GROWABLE_ARRAY_MARKER]) {
15 if (identical(length, _GROWABLE_ARRAY_MARKER)) { 15 if (identical(length, _GROWABLE_ARRAY_MARKER)) {
16 return new _GrowableList<E>(0); 16 return new _GrowableList<E>(0);
17 } 17 }
18 // All error handling on the length parameter is done at the implementation 18 // All error handling on the length parameter is done at the implementation
19 // of new _List. 19 // of new _List.
20 return new _List<E>(length); 20 return new _List<E>(length);
21 } 21 }
22 22
23 /* patch */ factory List.filled(int length, E fill) { 23 /* patch */ factory List.filled(int length, E fill, {bool growable: false}) {
24 // All error handling on the length parameter is done at the implementation 24 // All error handling on the length parameter is done at the implementation
25 // of new _List. 25 // of new _List.
26 var result = new _List<E>(length); 26 var result = growable ? new _GrowableList<E>(length) : new _List<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 elements, { bool growable: true }) { 35 /* patch */ factory List.from(Iterable elements, { bool growable: true }) {
36 if (elements is EfficientLength) { 36 if (elements is EfficientLength) {
(...skipping 24 matching lines...) Expand all
61 // [elements] contains elements that are already type checked. 61 // [elements] contains elements that are already type checked.
62 factory List._fromLiteral(List elements) { 62 factory List._fromLiteral(List elements) {
63 if (elements.isEmpty) { 63 if (elements.isEmpty) {
64 return new _GrowableList<E>(0); 64 return new _GrowableList<E>(0);
65 } 65 }
66 var result = new _GrowableList<E>.withData(elements); 66 var result = new _GrowableList<E>.withData(elements);
67 result._setLength(elements.length); 67 result._setLength(elements.length);
68 return result; 68 return result;
69 } 69 }
70 } 70 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/js_runtime/lib/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698