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

Side by Side Diff: pkg/serialization/lib/src/basic_rule.dart

Issue 12328104: Change new List(n) to return fixed length list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
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 part of serialization; 5 part of serialization;
6 6
7 // TODO(alanknight): Figure out how to reasonably separate out the things 7 // TODO(alanknight): Figure out how to reasonably separate out the things
8 // that require reflection without making the API more awkward. Or if that is 8 // that require reflection without making the API more awkward. Or if that is
9 // in fact necessary. Maybe the tree-shaking will just remove it if unused. 9 // in fact necessary. Maybe the tree-shaking will just remove it if unused.
10 10
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 /** 123 /**
124 * Configure this instance to use lists accessing fields by index as its 124 * Configure this instance to use lists accessing fields by index as its
125 * output. Instances can either produce maps or lists. The list representation 125 * output. Instances can either produce maps or lists. The list representation
126 * is much more compact and used by default. The map representation is 126 * is much more compact and used by default. The map representation is
127 * much easier to debug. The default is to use lists. 127 * much easier to debug. The default is to use lists.
128 */ 128 */
129 configureForLists() { 129 configureForLists() {
130 useMaps = false; 130 useMaps = false;
131 } 131 }
132 132
133 /** Create either a list or a map to hold the object's state, depending 133 /**
134 * Create either a list or a map to hold the object's state, depending
134 * on the [useMaps] variable. If using a Map, we wrap it in order to keep 135 * on the [useMaps] variable. If using a Map, we wrap it in order to keep
135 * the protocol compatible. See [configureForLists]/[configureForMaps]. 136 * the protocol compatible. See [configureForLists]/[configureForMaps].
137 *
138 * The list need to be growable for SimpleJson format to work.
floitsch 2013/02/26 13:54:19 If a list is returned, it is growable.
136 */ 139 */
137 createStateHolder() => 140 createStateHolder() =>
138 useMaps ? new _MapWrapper(fields.contents) : new List(fields.length); 141 useMaps ? new _MapWrapper(fields.contents)
floitsch 2013/02/26 13:54:19 I would prefer an 'if', and the length-assignment
142 : (new List()..length = fields.length);
139 143
140 /** 144 /**
141 * Wrap the state if it's passed in as a map, and if the keys are references, 145 * Wrap the state if it's passed in as a map, and if the keys are references,
142 * resolve them to the strings we expect. We leave the previous keys in there 146 * resolve them to the strings we expect. We leave the previous keys in there
143 * as well, as they shouldn't be harmful, and it costs more to remove them. 147 * as well, as they shouldn't be harmful, and it costs more to remove them.
144 */ 148 */
145 makeIndexableByNumber(state) { 149 makeIndexableByNumber(state) {
146 if (!(state is Map)) return state; 150 if (!(state is Map)) return state;
147 // TODO(alanknight): This is quite inefficient, and we do it twice per 151 // TODO(alanknight): This is quite inefficient, and we do it twice per
148 // instance. If the keys are references, we need to turn them into strings 152 // instance. If the keys are references, we need to turn them into strings
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 _MapWrapper(this.fieldList) : _map = new Map(); 627 _MapWrapper(this.fieldList) : _map = new Map();
624 _MapWrapper.fromMap(this._map, this.fieldList); 628 _MapWrapper.fromMap(this._map, this.fieldList);
625 629
626 operator [](key) => _map[fieldList[key].name]; 630 operator [](key) => _map[fieldList[key].name];
627 631
628 operator []=(key, value) { _map[fieldList[key].name] = value; } 632 operator []=(key, value) { _map[fieldList[key].name] = value; }
629 get length => _map.length; 633 get length => _map.length;
630 634
631 asMap() => _map; 635 asMap() => _map;
632 } 636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698