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

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

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « runtime/lib/array.dart ('k') | runtime/lib/async_sources.gypi » ('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 // 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 List<E> { 8 patch class List<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 result.length = length;
15 return result;
16 }
17
18 /* patch */ factory List.fixedLength(int length, {E fill: null}) {
19 if (length is! int || length < 0) {
20 throw new ArgumentError("Length must be a positive integer: $length.");
21 }
22 _ObjectArray<E> result = new _ObjectArray<E>(length);
23 if (fill != null) {
24 for (int i = 0; i < length; i++) {
25 result[i] = fill;
26 }
27 }
28 return result;
29 }
30
31 /* patch */ factory List.filled(int length, E fill) {
32 if (length is! int || length < 0) {
33 throw new ArgumentError("Length must be a positive integer: $length.");
34 }
35 _GrowableObjectArray<E> result =
36 new _GrowableObjectArray<E>.withCapacity(length < 4 ? 4 : length);
37 if (length != 0) {
38 result.length = length;
39 if (fill != null) {
40 for (int i = 0; i < length; i++) {
41 result[i] = fill;
42 }
43 }
44 }
45 return result;
15 } 46 }
16 47
17 // Factory constructing a mutable List from a parser generated List literal. 48 // Factory constructing a mutable List from a parser generated List literal.
18 // [elements] contains elements that are already type checked. 49 // [elements] contains elements that are already type checked.
19 factory List._fromLiteral(List elements) { 50 factory List._fromLiteral(List elements) {
20 var list = new List<E>(); 51 var list = new List<E>();
21 if (elements.length > 0) { 52 if (elements.length > 0) {
22 list._setData(elements); 53 list._setData(elements);
23 list.length = elements.length; 54 list.length = elements.length;
24 } 55 }
25 return list; 56 return list;
26 } 57 }
27 } 58 }
OLDNEW
« no previous file with comments | « runtime/lib/array.dart ('k') | runtime/lib/async_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698