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

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

Issue 8921033: Implement revised factories in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Factory class constructing mutable List and Map objects from parser generated 5 // Factory classes constructing mutable List and Map objects from parser
6 // list and map literals. 6 // generated list and map literals.
7 7
8 class _LiteralFactory { 8 class _ListLiteralFactory<E> {
9 // [elements] contains elements that are already type checked. 9 // [elements] contains elements that are already type checked.
10 factory List<E>.fromLiteral(List elements) { 10 factory List.fromLiteral(List elements) {
11 var list = new GrowableObjectArray<E>(); 11 var list = new GrowableObjectArray<E>();
12 if (elements.length > 0) { 12 if (elements.length > 0) {
13 list.backingArray = elements; 13 list.backingArray = elements;
14 list.length = elements.length; 14 list.length = elements.length;
15 } 15 }
16 return list; 16 return list;
17 } 17 }
18 }
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> {
19 // [elements] contains n key-value pairs. 24 // [elements] contains n key-value pairs.
20 // The keys are at position 2*n and are already type checked by the parser 25 // The keys are at position 2*n and are already type checked by the parser
21 // in checked mode. 26 // in checked mode.
22 // The values are at position 2*n+1 and are not yet type checked. 27 // The values are at position 2*n+1 and are not yet type checked.
23 factory Map<K, V>.fromLiteral(List elements) { 28 factory Map.fromLiteral(List elements) {
24 var map = new LinkedHashMap<String, V>(); 29 var map = new LinkedHashMap<String, V>();
25 var len = elements.length; 30 var len = elements.length;
26 for (int i = 1; i < len; i += 2) { 31 for (int i = 1; i < len; i += 2) {
27 map[elements[i - 1]] = elements[i]; 32 map[elements[i - 1]] = elements[i];
28 } 33 }
29 return map; 34 return map;
30 } 35 }
31 } 36 }
37
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698