| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Analysis to determine how to generate code for `LookupMap`s. | 5 /// Analysis to determine how to generate code for `LookupMap`s. |
| 6 library compiler.src.js_backend.lookup_map_analysis; | 6 library compiler.src.js_backend.lookup_map_analysis; |
| 7 | 7 |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/registry.dart' show Registry; | 9 import '../common/registry.dart' show Registry; |
| 10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 404 |
| 405 /// Marks that [key] has been seen, and thus, the corresponding entry in this | 405 /// Marks that [key] has been seen, and thus, the corresponding entry in this |
| 406 /// map should be considered reachable. | 406 /// map should be considered reachable. |
| 407 _markUsed(ConstantValue key) { | 407 _markUsed(ConstantValue key) { |
| 408 assert(!emitted); | 408 assert(!emitted); |
| 409 assert(unusedEntries.containsKey(key)); | 409 assert(unusedEntries.containsKey(key)); |
| 410 assert(!usedEntries.containsKey(key)); | 410 assert(!usedEntries.containsKey(key)); |
| 411 ConstantValue constant = unusedEntries.remove(key); | 411 ConstantValue constant = unusedEntries.remove(key); |
| 412 usedEntries[key] = constant; | 412 usedEntries[key] = constant; |
| 413 analysis.backend.registerCompileTimeConstant(constant, | 413 analysis.backend.registerCompileTimeConstant(constant, |
| 414 analysis.backend.compiler.globalDependencies, | 414 analysis.backend.compiler.globalDependencies); |
| 415 addForEmission: false); | |
| 416 } | 415 } |
| 417 | 416 |
| 418 /// Restores [original] to contain all of the entries marked as possibly used. | 417 /// Restores [original] to contain all of the entries marked as possibly used. |
| 419 void _prepareForEmission() { | 418 void _prepareForEmission() { |
| 420 ListConstantValue originalEntries = original.fields[analysis.entriesField]; | 419 ListConstantValue originalEntries = original.fields[analysis.entriesField]; |
| 421 DartType listType = originalEntries.type; | 420 DartType listType = originalEntries.type; |
| 422 List<ConstantValue> keyValuePairs = <ConstantValue>[]; | 421 List<ConstantValue> keyValuePairs = <ConstantValue>[]; |
| 423 usedEntries.forEach((key, value) { | 422 usedEntries.forEach((key, value) { |
| 424 keyValuePairs.add(key); | 423 keyValuePairs.add(key); |
| 425 keyValuePairs.add(value); | 424 keyValuePairs.add(value); |
| 426 }); | 425 }); |
| 427 | 426 |
| 428 // Note: we are restoring the entries here, see comment in [original]. | 427 // Note: we are restoring the entries here, see comment in [original]. |
| 429 if (singlePair) { | 428 if (singlePair) { |
| 430 assert (keyValuePairs.length == 0 || keyValuePairs.length == 2); | 429 assert (keyValuePairs.length == 0 || keyValuePairs.length == 2); |
| 431 if (keyValuePairs.length == 2) { | 430 if (keyValuePairs.length == 2) { |
| 432 original.fields[analysis.keyField] = keyValuePairs[0]; | 431 original.fields[analysis.keyField] = keyValuePairs[0]; |
| 433 original.fields[analysis.valueField] = keyValuePairs[1]; | 432 original.fields[analysis.valueField] = keyValuePairs[1]; |
| 434 } | 433 } |
| 435 } else { | 434 } else { |
| 436 original.fields[analysis.entriesField] = | 435 original.fields[analysis.entriesField] = |
| 437 new ListConstantValue(listType, keyValuePairs); | 436 new ListConstantValue(listType, keyValuePairs); |
| 438 } | 437 } |
| 439 } | 438 } |
| 440 } | 439 } |
| 441 | 440 |
| 442 final _validLookupMapVersionConstraint = | 441 final _validLookupMapVersionConstraint = |
| 443 new VersionConstraint.parse('^0.0.1'); | 442 new VersionConstraint.parse('^0.0.1'); |
| OLD | NEW |