| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 assert(isLookupMap(lookupMap)); | 198 assert(isLookupMap(lookupMap)); |
| 199 _lookupMaps.putIfAbsent(lookupMap, | 199 _lookupMaps.putIfAbsent(lookupMap, |
| 200 () => new _LookupMapInfo(lookupMap, this).._updateUsed()); | 200 () => new _LookupMapInfo(lookupMap, this).._updateUsed()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 /// Whether [key] is a constant value whose type overrides equals. | 203 /// Whether [key] is a constant value whose type overrides equals. |
| 204 bool _overridesEquals(ConstantValue key) { | 204 bool _overridesEquals(ConstantValue key) { |
| 205 if (key is ConstructedConstantValue) { | 205 if (key is ConstructedConstantValue) { |
| 206 ClassElement element = key.type.element; | 206 ClassElement element = key.type.element; |
| 207 return _typesWithEquals.putIfAbsent(element, () => | 207 return _typesWithEquals.putIfAbsent(element, () => |
| 208 element.lookupMember('==').enclosingClass != | 208 !element.lookupMember('==').enclosingClass.isObject); |
| 209 backend.compiler.objectClass); | |
| 210 } | 209 } |
| 211 return false; | 210 return false; |
| 212 } | 211 } |
| 213 | 212 |
| 214 /// Whether we need to preserve [key]. This is true for keys that are not | 213 /// Whether we need to preserve [key]. This is true for keys that are not |
| 215 /// candidates for tree-shaking in the first place (primitives and non-type | 214 /// candidates for tree-shaking in the first place (primitives and non-type |
| 216 /// const values overriding equals) and keys that we have seen in the program. | 215 /// const values overriding equals) and keys that we have seen in the program. |
| 217 bool _shouldKeep(ConstantValue key) => | 216 bool _shouldKeep(ConstantValue key) => |
| 218 key.isPrimitive || _inUse.contains(key) || _overridesEquals(key); | 217 key.isPrimitive || _inUse.contains(key) || _overridesEquals(key); |
| 219 | 218 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 } | 432 } |
| 434 } else { | 433 } else { |
| 435 original.fields[analysis.entriesField] = | 434 original.fields[analysis.entriesField] = |
| 436 new ListConstantValue(listType, keyValuePairs); | 435 new ListConstantValue(listType, keyValuePairs); |
| 437 } | 436 } |
| 438 } | 437 } |
| 439 } | 438 } |
| 440 | 439 |
| 441 final _validLookupMapVersionConstraint = | 440 final _validLookupMapVersionConstraint = |
| 442 new VersionConstraint.parse('^0.0.1'); | 441 new VersionConstraint.parse('^0.0.1'); |
| OLD | NEW |