Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 part of serialization; | 1 part of serialization; |
| 2 | 2 |
| 3 /** | 3 /** |
| 4 * An abstract class for serialization formats. Subclasses define how data | 4 * An abstract class for serialization formats. Subclasses define how data |
| 5 * is read or written to a particular output mechanism. | 5 * is read or written to a particular output mechanism. |
| 6 */ | 6 */ |
| 7 abstract class Format { | 7 abstract class Format { |
| 8 /** | 8 /** |
| 9 * Return true if this format stores primitives in their own area and uses | 9 * Return true if this format stores primitives in their own area and uses |
| 10 * references to them (e.g. [SimpleFlatFormat]) and false if primitives | 10 * references to them (e.g. [SimpleFlatFormat]) and false if primitives |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 if (storeRoundTripInfo) ruleData[i].add(rule.number); | 144 if (storeRoundTripInfo) ruleData[i].add(rule.number); |
| 145 } else if (each is Map) { | 145 } else if (each is Map) { |
| 146 jsonifyEntry(each, w); | 146 jsonifyEntry(each, w); |
| 147 if (storeRoundTripInfo) each[RULE] = rule.number; | 147 if (storeRoundTripInfo) each[RULE] = rule.number; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 /** | 152 /** |
| 153 * For one particular entry, which is either a Map or a List, update it | 153 * For one particular entry, which is either a Map or a List, update it |
| 154 * to turn References into a nested List/Map. | 154 * to turn References into a nested List/Map. If it's a Map, and the key |
|
Jennifer Messerly
2013/02/13 02:07:41
Unless this is purely an internal type, I'd put th
Alan Knight
2013/02/13 22:40:31
Done.
| |
| 155 * might be a reference, we need to bend over backwards to avoid | |
| 156 * concurrent modifications. | |
| 155 */ | 157 */ |
| 156 jsonifyEntry(map, Writer w) { | 158 jsonifyEntry(map, Writer w) { |
| 159 var keysToRemove = []; | |
| 160 var updates = new Map(); | |
| 157 keysAndValues(map).forEach((key, value) { | 161 keysAndValues(map).forEach((key, value) { |
| 158 if (value is Reference) map[key] = w.stateForReference(value); | 162 var newKey = (key is Reference) ? w.stateForReference(key) : key; |
| 163 if (value is Reference) updates[newKey] = w.stateForReference(value); | |
| 164 if (key != newKey) keysToRemove.add(key); | |
|
Jennifer Messerly
2013/02/13 02:07:41
We weren't removing keys before--is this also a bu
Alan Knight
2013/02/13 22:40:31
I added that, because one of the symptoms was an u
| |
| 159 }); | 165 }); |
| 166 keysToRemove.forEach((each) => map.remove(each)); | |
| 167 updates.forEach((k, v) => map[k] = v); | |
| 160 } | 168 } |
| 161 | 169 |
| 162 /** | 170 /** |
| 163 * Read serialized data saved in this format, which should look like | 171 * Read serialized data saved in this format, which should look like |
| 164 * either a simple type, a List or a Map and return the Map | 172 * either a simple type, a List or a Map and return the Map |
| 165 * representation that the reader expects, with top-level | 173 * representation that the reader expects, with top-level |
| 166 * entries for "rules", "data", and "roots". Nested lists/maps will be | 174 * entries for "rules", "data", and "roots". Nested lists/maps will be |
| 167 * converted into Reference objects. Note that if the data was not written | 175 * converted into Reference objects. Note that if the data was not written |
| 168 * with [storeRoundTripInfo] true this will fail. | 176 * with [storeRoundTripInfo] true this will fail. |
| 169 */ | 177 */ |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 return new Reference(r, a, b); | 464 return new Reference(r, a, b); |
| 457 } | 465 } |
| 458 } | 466 } |
| 459 | 467 |
| 460 /** Return the next element from the input. */ | 468 /** Return the next element from the input. */ |
| 461 _next(Iterator input) { | 469 _next(Iterator input) { |
| 462 input.moveNext(); | 470 input.moveNext(); |
| 463 return input.current; | 471 return input.current; |
| 464 } | 472 } |
| 465 } | 473 } |
| OLD | NEW |