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

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

Issue 11312122: Change List constructors. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Address comments and fix. Created 8 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 | 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 // Note that the optimizing compiler depends on the algorithm which 5 // Note that the optimizing compiler depends on the algorithm which
6 // returns a _GrowableObjectArray if length is null, otherwise returns 6 // returns a _GrowableObjectArray if length is null, otherwise returns
7 // fixed size array. 7 // fixed size array.
8 patch class _ListImpl<E> { 8 patch class _ListImpl<E> {
9 /* patch */ factory List([int length = null]) { 9 /* patch */ factory List([int length = 0]) {
10 if (length === null) { 10 if (length is! int || length < 0) {
11 return new _GrowableObjectArray<E>(); 11 throw new ArgumentError("Length must be a positive integer: $length.");
12 } else {
13 return new _ObjectArray<E>(length);
14 } 12 }
13 _GrowableObjectArray<E> result = new _GrowableObjectArray<E>();
14 if (length != 0) {
Lasse Reichstein Nielsen 2012/11/12 11:31:06 Don't check, just set the length. It's correct for
floitsch 2012/11/12 13:21:50 Done.
15 result.length = length;
16 }
17 return result;
18 }
19
20 /* patch */ factory List.fixedLength(int length, {E fill: null}) {
21 if (length is! int || length < 0) {
22 throw new ArgumentError("Length must be a positive integer: $length.");
23 }
24 _ObjectArray<E> result = new _ObjectArray<E>(length);
25 if (fill != null) {
26 for (int i = 0; i < length; i++) {
27 result[i] = fill;
28 }
29 }
30 return result;
31 }
32
33 /* patch */ factory List.filled(int length, E fill) {
34 if (length is! int || length < 0) {
35 throw new ArgumentError("Length must be a positive integer: $length.");
36 }
37 _GrowableObjectArray<E> result =
38 new _GrowableObjectArray<E>.withCapacity(length < 4 ? 4 : length);
39 if (length != 0) {
40 result.length = length;
41 if (fill != null) {
42 for (int i = 0; i < length; i++) {
43 result[i] = fill;
44 }
45 }
46 }
47 return result;
15 } 48 }
16 49
17 /* patch */ factory List.from(Iterable<E> other) { 50 /* patch */ factory List.from(Iterable<E> other) {
18 _GrowableObjectArray<E> list = new _GrowableObjectArray<E>(); 51 _GrowableObjectArray<E> list = new _GrowableObjectArray<E>();
19 for (final e in other) { 52 for (final e in other) {
20 list.add(e); 53 list.add(e);
21 } 54 }
22 return list; 55 return list;
23 } 56 }
24 } 57 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/string_base.dart » ('j') | sdk/lib/_internal/compiler/implementation/lib/core_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698