Skip to content

Commit 9651c87

Browse files
committed
perf: use HashMaps instead of LinkedHashMaps where possible
1 parent 42e53b8 commit 9651c87

22 files changed

+49
-43
lines changed

lib/animate/css_animate.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ class CssAnimate implements Animate {
134134
@Injectable()
135135
class CssAnimationMap {
136136
final Map<dom.Element, Map<String, CssAnimation>> cssAnimations
137-
= new Map<dom.Element, Map<String, CssAnimation>>();
137+
= new HashMap<dom.Element, Map<String, CssAnimation>>();
138138

139139
void track(CssAnimation animation) {
140140
var animations = cssAnimations.putIfAbsent(animation.element,
141-
() => <String, CssAnimation>{});
141+
() => new HashMap<String, CssAnimation>());
142142
animations[animation.eventClass] = animation;
143143
}
144144

lib/animate/module.dart

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import 'package:di/di.dart';
113113
'angular.animate'
114114
])
115115
import 'dart:mirrors' show MirrorsUsed;
116+
import 'dart:collection';
116117

117118
part 'animations.dart';
118119
part 'animation_loop.dart';

lib/change_detection/dirty_checking_change_detector.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class DirtyCheckingRecord<H> implements Record<H>, WatchRecord<H> {
543543
final Object _INITIAL_ = new Object();
544544

545545
class _MapChangeRecord<K, V> implements MapChangeRecord<K, V> {
546-
final _records = new Map<dynamic, KeyValueRecord>();
546+
final _records = new HashMap<dynamic, KeyValueRecord>();
547547
Map _map;
548548

549549
Map get map => _map;
@@ -1414,7 +1414,7 @@ class _DuplicateItemRecordList {
14141414
* The list of duplicates is implemented by [_DuplicateItemRecordList].
14151415
*/
14161416
class DuplicateMap {
1417-
final map = <dynamic, _DuplicateItemRecordList>{};
1417+
final map = new HashMap<dynamic, _DuplicateItemRecordList>();
14181418

14191419
void put(ItemRecord record, [ItemRecord insertBefore = null]) {
14201420
map.putIfAbsent(record.item, () => new _DuplicateItemRecordList()).add(record, insertBefore);

lib/change_detection/prototype_map.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ part of angular.watch_group;
22

33
class PrototypeMap<K, V> implements Map<K,V> {
44
final Map<K, V> prototype;
5-
final Map<K, V> self = new Map();
5+
final Map<K, V> self = new HashMap();
66

77
PrototypeMap(this.prototype);
88

lib/change_detection/watch_group.dart

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
library angular.watch_group;
22

33
import 'package:angular/change_detection/change_detection.dart';
4+
import 'dart:collection';
45

56
part 'linked_list.dart';
67
part 'ast.dart';
@@ -119,7 +120,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
119120
: id = '',
120121
_rootGroup = null,
121122
_parentWatchGroup = null,
122-
_cache = new Map<String, WatchRecord<_Handler>>()
123+
_cache = new HashMap<String, WatchRecord<_Handler>>()
123124
{
124125
_marker.watchGrp = this;
125126
_evalWatchTail = _evalWatchHead = _marker;
@@ -289,7 +290,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
289290
this,
290291
_changeDetector.newGroup(),
291292
context == null ? this.context : context,
292-
<String, WatchRecord<_Handler>>{},
293+
new HashMap<String, WatchRecord<_Handler>>(),
293294
_rootGroup == null ? this : _rootGroup);
294295
_WatchGroupList._add(this, childGroup);
295296
var marker = childGroup._marker;
@@ -680,7 +681,7 @@ class _NamedArgHandler extends _ArgHandler {
680681

681682
void acceptValue(object) {
682683
if (watchRecord.namedArgs == null) {
683-
watchRecord.namedArgs = new Map<Symbol, dynamic>();
684+
watchRecord.namedArgs = new HashMap<Symbol, dynamic>();
684685
}
685686
watchRecord.dirtyArgs = true;
686687
watchRecord.namedArgs[name] = object;

lib/core/cache.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ abstract class Cache<K, V> {
4343
* An unbounded cache.
4444
*/
4545
class UnboundedCache<K, V> implements Cache<K, V> {
46-
Map<K, V> _entries = <K, V>{};
46+
Map<K, V> _entries = new HashMap<K, V>();
4747
int _hits = 0;
4848
int _misses = 0;
4949

lib/core/interpolate.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ part of angular.core_internal;
1010
*/
1111
@Injectable()
1212
class Interpolate implements Function {
13-
var _cache = {};
13+
var _cache = new HashMap();
1414
/**
1515
* Compiles markup text into expression.
1616
*

lib/core/parser/static_parser.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StaticParserFunctions {
1616
class StaticParser implements Parser<Expression> {
1717
final StaticParserFunctions _functions;
1818
final DynamicParser _fallbackParser;
19-
final _cache = <String, Expression>{};
19+
final _cache = new HashMap<String, Expression>();
2020
StaticParser(this._functions, this._fallbackParser);
2121

2222
Expression call(String input) {

lib/core/registry_dynamic.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ library angular.core_dynamic;
33
import 'dart:mirrors';
44
import 'package:angular/core/annotation_src.dart';
55
import 'package:angular/core/registry.dart';
6+
import 'dart:collection';
67

78
export 'package:angular/core/registry.dart' show
89
MetadataExtractor;
910

10-
var _fieldMetadataCache = new Map<Type, Map<String, DirectiveAnnotation>>();
11+
var _fieldMetadataCache = new HashMap<Type, Map<String, DirectiveAnnotation>>();
1112

1213
class DynamicMetadataExtractor implements MetadataExtractor {
1314
final _fieldAnnotations = [
@@ -41,7 +42,7 @@ class DynamicMetadataExtractor implements MetadataExtractor {
4142
var match;
4243
var fieldMetadata = fieldMetadataExtractor(type);
4344
if (fieldMetadata.isNotEmpty) {
44-
var newMap = annotation.map == null ? {} : new Map.from(annotation.map);
45+
var newMap = annotation.map == null ? new HashMap() : new HashMap.from(annotation.map);
4546
fieldMetadata.forEach((String fieldName, DirectiveAnnotation ann) {
4647
var attrName = ann.attrName;
4748
if (newMap.containsKey(attrName)) {
@@ -60,11 +61,11 @@ class DynamicMetadataExtractor implements MetadataExtractor {
6061
_fieldMetadataCache.putIfAbsent(type, () => _fieldMetadataExtractor(reflectType(type)));
6162

6263
Map<String, DirectiveAnnotation> _fieldMetadataExtractor(ClassMirror cm) {
63-
var fields = <String, DirectiveAnnotation>{};
64+
var fields = new HashMap<String, DirectiveAnnotation>();
6465
if(cm.superclass != null) {
6566
fields.addAll(_fieldMetadataExtractor(cm.superclass));
6667
} else {
67-
fields = {};
68+
fields = new HashMap();
6869
}
6970
Map<Symbol, DeclarationMirror> declarations = cm.declarations;
7071
declarations.forEach((symbol, dm) {

lib/core/scope.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class Scope {
275275
WatchGroup group = canChangeModel ? _readWriteGroup : _readOnlyGroup;
276276
return group.watch(ast, reactionFn);
277277
}
278-
static Map _oneTimeWarnings = {};
278+
static Map _oneTimeWarnings = new HashMap();
279279

280280
dynamic eval(expression, [Map locals]) {
281281
assert(isAttached);
@@ -369,8 +369,8 @@ class Scope {
369369

370370
Map<bool,int> _verifyStreams(parentScope, prefix, log) {
371371
assert(_parentScope == parentScope);
372-
var counts = {};
373-
var typeCounts = _streams == null ? {} : _streams._typeCounts;
372+
var counts = new HashMap();
373+
var typeCounts = _streams == null ? new HashMap() : _streams._typeCounts;
374374
var connection = _streams != null && _streams._scope == this ? '=' : '-';
375375
log..add(prefix)..add(hashCode)..add(connection)..add(typeCounts)..add('\n');
376376
if (_streams == null) {
@@ -862,14 +862,14 @@ class _Streams {
862862
/// Scope we belong to.
863863
final Scope _scope;
864864
/// [Stream]s for [_scope] only
865-
final _streams = new Map<String, ScopeStream>();
865+
final _streams = new HashMap<String, ScopeStream>();
866866
/// Child [Scope] event counts.
867867
final Map<String, int> _typeCounts;
868868

869869
_Streams(this._scope, this._exceptionHandler, _Streams inheritStreams)
870870
: _typeCounts = inheritStreams == null
871-
? <String, int>{}
872-
: new Map.from(inheritStreams._typeCounts);
871+
? new HashMap<String, int>()
872+
: new HashMap.from(inheritStreams._typeCounts);
873873

874874
static ScopeEvent emit(Scope scope, String name, data) {
875875
var event = new ScopeEvent(name, scope, data);

lib/core_dom/directive.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NodeAttrs {
1818
final dom.Element element;
1919

2020
Map<String, List<_AttributeChanged>> _observers;
21-
final _mustacheAttrs = <String, _MustacheAttr>{};
21+
final _mustacheAttrs = new HashMap<String, _MustacheAttr>();
2222

2323
NodeAttrs(this.element);
2424

@@ -49,7 +49,7 @@ class NodeAttrs {
4949
* [:true:]
5050
*/
5151
observe(String attrName, notifyFn(String value)) {
52-
if (_observers == null) _observers = <String, List<_AttributeChanged>>{};
52+
if (_observers == null) _observers = new HashMap<String, List<_AttributeChanged>>();
5353
_observers.putIfAbsent(attrName, () => <_AttributeChanged>[])
5454
.add(notifyFn);
5555

lib/core_dom/element_binder_builder.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class ElementBinderBuilder {
4040
final FormatterMap _formatters;
4141

4242
/// "on-*" attribute names and values, added by a [DirectiveSelector]
43-
final onEvents = <String, String>{};
43+
final onEvents = new HashMap<String, String>();
4444
/// "bind-*" attribute names and values, added by a [DirectiveSelector]
45-
final bindAttrs = <String, AST>{};
45+
final bindAttrs = new HashMap<String, AST>();
4646

4747
final decorators = <DirectiveRef>[];
4848
DirectiveRef template;

lib/core_dom/event_handler.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class EventHandler {
3131
dom.Node _rootNode;
3232
final Expando _expando;
3333
final ExceptionHandler _exceptionHandler;
34-
final _listeners = <String, Function>{};
34+
final _listeners = new HashMap<String, Function>();
3535

3636
EventHandler(this._rootNode, this._expando, this._exceptionHandler);
3737

lib/core_dom/http.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class HttpDefaults {
369369
*/
370370
@Injectable()
371371
class Http {
372-
var _pendingRequests = <String, async.Future<HttpResponse>>{};
372+
var _pendingRequests = new HashMap<String, async.Future<HttpResponse>>();
373373
BrowserCookies _cookies;
374374
LocationWrapper _location;
375375
UrlRewriter _rewriter;
@@ -649,7 +649,7 @@ class Http {
649649
static Map<String, String> parseHeaders(dom.HttpRequest value) {
650650
var headers = value.getAllResponseHeaders();
651651

652-
var parsed = {};
652+
var parsed = new HashMap();
653653

654654
if (headers == null) return parsed;
655655

lib/core_dom/module_internal.dart

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:angular/change_detection/ast_parser.dart';
2020
import 'package:angular/core/registry.dart';
2121

2222
import 'package:angular/directive/module.dart' show NgBaseCss;
23+
import 'dart:collection';
2324

2425
part 'animation.dart';
2526
part 'view.dart';

lib/core_dom/ng_element.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class NgElement {
88
final Scope _scope;
99
final Animate _animate;
1010

11-
final _classesToUpdate = <String, bool>{};
12-
final _attributesToUpdate = <String, dynamic>{};
11+
final _classesToUpdate = new HashMap<String, bool>();
12+
final _attributesToUpdate = new HashMap<String, dynamic>();
1313

1414
bool _writeScheduled = false;
1515

lib/core_dom/selector.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DirectiveSelector {
6262
ElementBinderBuilder builder = _binderFactory.builder(_formatters, _directives);
6363
List<_ElementSelector> partialSelection;
6464
final classes = new Set<String>();
65-
final attrs = <String, String>{};
65+
final attrs = new HashMap<String, String>();
6666

6767
dom.Element element = node;
6868
String nodeName = element.tagName.toLowerCase();
@@ -234,14 +234,14 @@ _addRefs(ElementBinderBuilder builder, List<_Directive> directives, dom.Node nod
234234
class _ElementSelector {
235235
final String _name;
236236

237-
final _elementMap = <String, List<_Directive>>{};
238-
final _elementPartialMap = <String, _ElementSelector>{};
237+
final _elementMap = new HashMap<String, List<_Directive>>();
238+
final _elementPartialMap = new HashMap<String, _ElementSelector>();
239239

240-
final _classMap = <String, List<_Directive>>{};
241-
final _classPartialMap = <String, _ElementSelector>{};
240+
final _classMap = new HashMap<String, List<_Directive>>();
241+
final _classPartialMap = new HashMap<String, _ElementSelector>();
242242

243-
final _attrValueMap = <String, Map<String, List<_Directive>>>{};
244-
final _attrValuePartialMap = <String, Map<String, _ElementSelector>>{};
243+
final _attrValueMap = new HashMap<String, Map<String, List<_Directive>>>();
244+
final _attrValuePartialMap = new HashMap<String, Map<String, _ElementSelector>>();
245245

246246
_ElementSelector(this._name);
247247

@@ -268,12 +268,12 @@ class _ElementSelector {
268268
}
269269
} else if ((name = part.attrName) != null) {
270270
if (terminal) {
271-
elSelector._attrValueMap.putIfAbsent(name, () => <String, List<_Directive>>{})
271+
elSelector._attrValueMap.putIfAbsent(name, () => new HashMap<String, List<_Directive>>())
272272
.putIfAbsent(part.attrValue, () => [])
273273
.add(directive);
274274
} else {
275275
elSelector = elSelector._attrValuePartialMap
276-
.putIfAbsent(name, () => <String, _ElementSelector>{})
276+
.putIfAbsent(name, () => new HashMap<String, _ElementSelector>())
277277
.putIfAbsent(part.attrValue, () => new _ElementSelector(name));
278278
}
279279
} else {
@@ -349,7 +349,7 @@ class _ElementSelector {
349349

350350
// A global cache for the _matchingKey RegExps. The size is bounded by
351351
// the number of attribute directive selectors used in the application.
352-
static var _matchingKeyCache = <String, RegExp>{};
352+
static var _matchingKeyCache = new HashMap<String, RegExp>();
353353

354354
String _matchingKey(Iterable<String> keys, String attrName) =>
355355
keys.firstWhere((key) =>

lib/directive/module.dart

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import 'package:angular/utils.dart';
2828
import 'package:angular/change_detection/watch_group.dart';
2929
import 'package:angular/change_detection/change_detection.dart';
3030
import 'package:angular/directive/static_keys.dart';
31+
import 'dart:collection';
3132

3233
part 'a_href.dart';
3334
part 'ng_base_css.dart';

lib/directive/ng_events.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class NgEvent {
133133
// Is it better to use a map of listeners or have 29 properties on this
134134
// object? One would pretty much only assign to one or two of those
135135
// properties. I'm opting for the map since it's less boilerplate code.
136-
var listeners = {};
136+
var listeners = new HashMap();
137137
final dom.Element element;
138138
final Scope scope;
139139

lib/directive/ng_repeat.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class NgRepeat {
107107
if (trackByExpr != null) {
108108
Expression trackBy = _parser(trackByExpr);
109109
_generateId = ((key, value, index) {
110-
final context = <String, Object>{}
110+
final context = new HashMap<String, Object>()
111111
..[_valueIdentifier] = value
112112
..[r'$index'] = index
113113
..[r'$id'] = (obj) => obj;

lib/routing/module.dart

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ import 'package:angular/core_dom/module_internal.dart';
133133
import 'package:route_hierarchical/client.dart';
134134

135135
import 'package:angular/routing/static_keys.dart';
136+
import 'dart:collection';
136137

137138
part 'routing.dart';
138139
part 'ng_view.dart';

lib/routing/ng_view.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class NgView implements DetachAware, RouteProvider {
138138
String get routeName => _viewRoute.name;
139139

140140
Map<String, String> get parameters {
141-
var res = <String, String>{};
141+
var res = new HashMap<String, String>();
142142
var p = _viewRoute;
143143
while (p != null) {
144144
res.addAll(p.parameters);

0 commit comments

Comments
 (0)