| OLD | NEW |
| 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 = 0]) { | 9 /* patch */ factory List([int length = 0]) { |
| 10 if ((length is! int) || (length < 0)) { | 10 if ((length is! int) || (length < 0)) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 for (int i = 0; i < length; i++) { | 38 for (int i = 0; i < length; i++) { |
| 39 result[i] = fill; | 39 result[i] = fill; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 return result; | 42 return result; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Factory constructing a mutable List from a parser generated List literal. | 45 // Factory constructing a mutable List from a parser generated List literal. |
| 46 // [elements] contains elements that are already type checked. | 46 // [elements] contains elements that are already type checked. |
| 47 factory List._fromLiteral(List elements) { | 47 factory List._fromLiteral(List elements) { |
| 48 var list = new List<E>(); | 48 if (elements.isEmpty) { |
| 49 if (elements.length > 0) { | 49 return new _GrowableObjectArray<E>(0); |
| 50 list._setData(elements); | |
| 51 list.length = elements.length; | |
| 52 } | 50 } |
| 53 return list; | 51 var result = new _GrowableObjectArray<E>.withData(elements); |
| 52 result._setLength(elements.length); |
| 53 return result; |
| 54 } | 54 } |
| 55 | 55 |
| 56 static void _throwArgumentError(int length) { | 56 static void _throwArgumentError(int length) { |
| 57 throw new ArgumentError("Length must be a positive integer: $length."); | 57 throw new ArgumentError("Length must be a positive integer: $length."); |
| 58 } | 58 } |
| 59 } | 59 } |
| OLD | NEW |