| 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 import 'dart:collection' show HashMap, HashSet; | 5 import 'dart:collection' show HashMap, HashSet, LinkedHashMap; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; | 8 import 'package:analyzer/dart/element/type.dart'; |
| 9 | 9 |
| 10 import '../js_ast/js_ast.dart' as JS; | 10 import '../js_ast/js_ast.dart' as JS; |
| 11 import '../js_ast/js_ast.dart' show js; | 11 import '../js_ast/js_ast.dart' show js; |
| 12 import 'js_names.dart' as JS; | 12 import 'js_names.dart' as JS; |
| 13 | 13 |
| 14 Set<TypeParameterElement> freeTypeParameters(DartType t) { | 14 Set<TypeParameterElement> freeTypeParameters(DartType t) { |
| 15 var result = new HashSet<TypeParameterElement>(); | 15 var result = new HashSet<TypeParameterElement>(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 find(t); | 28 find(t); |
| 29 return result; | 29 return result; |
| 30 } | 30 } |
| 31 | 31 |
| 32 /// _CacheTable tracks cache variables for variables that | 32 /// _CacheTable tracks cache variables for variables that |
| 33 /// are emitted in place with a hoisted variable for a cache. | 33 /// are emitted in place with a hoisted variable for a cache. |
| 34 class _CacheTable { | 34 class _CacheTable { |
| 35 /// Mapping from types to their canonical names. | 35 /// Mapping from types to their canonical names. |
| 36 final _names = new HashMap<DartType, JS.TemporaryId>(); | 36 // Use a LinkedHashMap to maintain key insertion order so the generated code |
| 37 // is stable under slight perturbation. (If this is not good enough we could |
| 38 // sort by name to canonicalize order.) |
| 39 final _names = new LinkedHashMap<DartType, JS.TemporaryId>(); |
| 37 Iterable<DartType> get keys => _names.keys.toList(); | 40 Iterable<DartType> get keys => _names.keys.toList(); |
| 38 | 41 |
| 39 JS.Statement _dischargeType(DartType type) { | 42 JS.Statement _dischargeType(DartType type) { |
| 40 var name = _names.remove(type); | 43 var name = _names.remove(type); |
| 41 if (name != null) { | 44 if (name != null) { |
| 42 return js.statement('let #;', [name]); | 45 return js.statement('let #;', [name]); |
| 43 } | 46 } |
| 44 return null; | 47 return null; |
| 45 } | 48 } |
| 46 | 49 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 assert(hoistType != null); | 223 assert(hoistType != null); |
| 221 var table = hoistType | 224 var table = hoistType |
| 222 ? (definite ? _definiteGenerators : _generators) | 225 ? (definite ? _definiteGenerators : _generators) |
| 223 : (definite ? _definiteCacheNames : _cacheNames); | 226 : (definite ? _definiteCacheNames : _cacheNames); |
| 224 if (!table.isNamed(type)) { | 227 if (!table.isNamed(type)) { |
| 225 if (recordScopeDependencies(type)) return typeRep; | 228 if (recordScopeDependencies(type)) return typeRep; |
| 226 } | 229 } |
| 227 return table.nameType(type, typeRep); | 230 return table.nameType(type, typeRep); |
| 228 } | 231 } |
| 229 } | 232 } |
| OLD | NEW |