| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Factory classes constructing mutable List and Map objects from parser | |
| 6 // generated list and map literals. | |
| 7 | |
| 8 class _ListLiteralFactory<E> { | |
| 9 // [elements] contains elements that are already type checked. | |
| 10 factory List.fromLiteral(List elements) { | |
| 11 var list = new List<E>(); | |
| 12 if (elements.length > 0) { | |
| 13 list._setData(elements); | |
| 14 list.length = elements.length; | |
| 15 } | |
| 16 return list; | |
| 17 } | |
| 18 } | |
| 19 | |
| 20 // Factory class constructing mutable List and Map objects from parser generated | |
| 21 // list and map literals. | |
| 22 | |
| 23 class _MapLiteralFactory<K, V> { | |
| 24 // [elements] contains n key-value pairs. | |
| 25 // The keys are at position 2*n and are already type checked by the parser | |
| 26 // in checked mode. | |
| 27 // The values are at position 2*n+1 and are not yet type checked. | |
| 28 factory Map.fromLiteral(List elements) { | |
| 29 var map = new LinkedHashMap<String, V>(); | |
| 30 var len = elements.length; | |
| 31 for (int i = 1; i < len; i += 2) { | |
| 32 map[elements[i - 1]] = elements[i]; | |
| 33 } | |
| 34 return map; | |
| 35 } | |
| 36 } | |
| 37 | |
| OLD | NEW |