Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
perf: use HashMaps instead of LinkedHashMaps where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Jun 12, 2014
1 parent 42e53b8 commit 9651c87
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/animate/css_animate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ class CssAnimate implements Animate {
@Injectable()
class CssAnimationMap {
final Map<dom.Element, Map<String, CssAnimation>> cssAnimations
= new Map<dom.Element, Map<String, CssAnimation>>();
= new HashMap<dom.Element, Map<String, CssAnimation>>();

void track(CssAnimation animation) {
var animations = cssAnimations.putIfAbsent(animation.element,
() => <String, CssAnimation>{});
() => new HashMap<String, CssAnimation>());
animations[animation.eventClass] = animation;
}

Expand Down
1 change: 1 addition & 0 deletions lib/animate/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import 'package:di/di.dart';
'angular.animate'
])
import 'dart:mirrors' show MirrorsUsed;
import 'dart:collection';

part 'animations.dart';
part 'animation_loop.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/change_detection/dirty_checking_change_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class DirtyCheckingRecord<H> implements Record<H>, WatchRecord<H> {
final Object _INITIAL_ = new Object();

class _MapChangeRecord<K, V> implements MapChangeRecord<K, V> {
final _records = new Map<dynamic, KeyValueRecord>();
final _records = new HashMap<dynamic, KeyValueRecord>();
Map _map;

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

void put(ItemRecord record, [ItemRecord insertBefore = null]) {
map.putIfAbsent(record.item, () => new _DuplicateItemRecordList()).add(record, insertBefore);
Expand Down
2 changes: 1 addition & 1 deletion lib/change_detection/prototype_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ part of angular.watch_group;

class PrototypeMap<K, V> implements Map<K,V> {
final Map<K, V> prototype;
final Map<K, V> self = new Map();
final Map<K, V> self = new HashMap();

PrototypeMap(this.prototype);

Expand Down
7 changes: 4 additions & 3 deletions lib/change_detection/watch_group.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library angular.watch_group;

import 'package:angular/change_detection/change_detection.dart';
import 'dart:collection';

part 'linked_list.dart';
part 'ast.dart';
Expand Down Expand Up @@ -119,7 +120,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
: id = '',
_rootGroup = null,
_parentWatchGroup = null,
_cache = new Map<String, WatchRecord<_Handler>>()
_cache = new HashMap<String, WatchRecord<_Handler>>()
{
_marker.watchGrp = this;
_evalWatchTail = _evalWatchHead = _marker;
Expand Down Expand Up @@ -289,7 +290,7 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
this,
_changeDetector.newGroup(),
context == null ? this.context : context,
<String, WatchRecord<_Handler>>{},
new HashMap<String, WatchRecord<_Handler>>(),
_rootGroup == null ? this : _rootGroup);
_WatchGroupList._add(this, childGroup);
var marker = childGroup._marker;
Expand Down Expand Up @@ -680,7 +681,7 @@ class _NamedArgHandler extends _ArgHandler {

void acceptValue(object) {
if (watchRecord.namedArgs == null) {
watchRecord.namedArgs = new Map<Symbol, dynamic>();
watchRecord.namedArgs = new HashMap<Symbol, dynamic>();
}
watchRecord.dirtyArgs = true;
watchRecord.namedArgs[name] = object;
Expand Down
2 changes: 1 addition & 1 deletion lib/core/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class Cache<K, V> {
* An unbounded cache.
*/
class UnboundedCache<K, V> implements Cache<K, V> {
Map<K, V> _entries = <K, V>{};
Map<K, V> _entries = new HashMap<K, V>();
int _hits = 0;
int _misses = 0;

Expand Down
2 changes: 1 addition & 1 deletion lib/core/interpolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ part of angular.core_internal;
*/
@Injectable()
class Interpolate implements Function {
var _cache = {};
var _cache = new HashMap();
/**
* Compiles markup text into expression.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/core/parser/static_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class StaticParserFunctions {
class StaticParser implements Parser<Expression> {
final StaticParserFunctions _functions;
final DynamicParser _fallbackParser;
final _cache = <String, Expression>{};
final _cache = new HashMap<String, Expression>();
StaticParser(this._functions, this._fallbackParser);

Expression call(String input) {
Expand Down
9 changes: 5 additions & 4 deletions lib/core/registry_dynamic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ library angular.core_dynamic;
import 'dart:mirrors';
import 'package:angular/core/annotation_src.dart';
import 'package:angular/core/registry.dart';
import 'dart:collection';

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

var _fieldMetadataCache = new Map<Type, Map<String, DirectiveAnnotation>>();
var _fieldMetadataCache = new HashMap<Type, Map<String, DirectiveAnnotation>>();

class DynamicMetadataExtractor implements MetadataExtractor {
final _fieldAnnotations = [
Expand Down Expand Up @@ -41,7 +42,7 @@ class DynamicMetadataExtractor implements MetadataExtractor {
var match;
var fieldMetadata = fieldMetadataExtractor(type);
if (fieldMetadata.isNotEmpty) {
var newMap = annotation.map == null ? {} : new Map.from(annotation.map);
var newMap = annotation.map == null ? new HashMap() : new HashMap.from(annotation.map);
fieldMetadata.forEach((String fieldName, DirectiveAnnotation ann) {
var attrName = ann.attrName;
if (newMap.containsKey(attrName)) {
Expand All @@ -60,11 +61,11 @@ class DynamicMetadataExtractor implements MetadataExtractor {
_fieldMetadataCache.putIfAbsent(type, () => _fieldMetadataExtractor(reflectType(type)));

Map<String, DirectiveAnnotation> _fieldMetadataExtractor(ClassMirror cm) {
var fields = <String, DirectiveAnnotation>{};
var fields = new HashMap<String, DirectiveAnnotation>();
if(cm.superclass != null) {
fields.addAll(_fieldMetadataExtractor(cm.superclass));
} else {
fields = {};
fields = new HashMap();
}
Map<Symbol, DeclarationMirror> declarations = cm.declarations;
declarations.forEach((symbol, dm) {
Expand Down
12 changes: 6 additions & 6 deletions lib/core/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class Scope {
WatchGroup group = canChangeModel ? _readWriteGroup : _readOnlyGroup;
return group.watch(ast, reactionFn);
}
static Map _oneTimeWarnings = {};
static Map _oneTimeWarnings = new HashMap();

dynamic eval(expression, [Map locals]) {
assert(isAttached);
Expand Down Expand Up @@ -369,8 +369,8 @@ class Scope {

Map<bool,int> _verifyStreams(parentScope, prefix, log) {
assert(_parentScope == parentScope);
var counts = {};
var typeCounts = _streams == null ? {} : _streams._typeCounts;
var counts = new HashMap();
var typeCounts = _streams == null ? new HashMap() : _streams._typeCounts;
var connection = _streams != null && _streams._scope == this ? '=' : '-';
log..add(prefix)..add(hashCode)..add(connection)..add(typeCounts)..add('\n');
if (_streams == null) {
Expand Down Expand Up @@ -862,14 +862,14 @@ class _Streams {
/// Scope we belong to.
final Scope _scope;
/// [Stream]s for [_scope] only
final _streams = new Map<String, ScopeStream>();
final _streams = new HashMap<String, ScopeStream>();
/// Child [Scope] event counts.
final Map<String, int> _typeCounts;

_Streams(this._scope, this._exceptionHandler, _Streams inheritStreams)
: _typeCounts = inheritStreams == null
? <String, int>{}
: new Map.from(inheritStreams._typeCounts);
? new HashMap<String, int>()
: new HashMap.from(inheritStreams._typeCounts);

static ScopeEvent emit(Scope scope, String name, data) {
var event = new ScopeEvent(name, scope, data);
Expand Down
4 changes: 2 additions & 2 deletions lib/core_dom/directive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class NodeAttrs {
final dom.Element element;

Map<String, List<_AttributeChanged>> _observers;
final _mustacheAttrs = <String, _MustacheAttr>{};
final _mustacheAttrs = new HashMap<String, _MustacheAttr>();

NodeAttrs(this.element);

Expand Down Expand Up @@ -49,7 +49,7 @@ class NodeAttrs {
* [:true:]
*/
observe(String attrName, notifyFn(String value)) {
if (_observers == null) _observers = <String, List<_AttributeChanged>>{};
if (_observers == null) _observers = new HashMap<String, List<_AttributeChanged>>();
_observers.putIfAbsent(attrName, () => <_AttributeChanged>[])
.add(notifyFn);

Expand Down
4 changes: 2 additions & 2 deletions lib/core_dom/element_binder_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class ElementBinderBuilder {
final FormatterMap _formatters;

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

final decorators = <DirectiveRef>[];
DirectiveRef template;
Expand Down
2 changes: 1 addition & 1 deletion lib/core_dom/event_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EventHandler {
dom.Node _rootNode;
final Expando _expando;
final ExceptionHandler _exceptionHandler;
final _listeners = <String, Function>{};
final _listeners = new HashMap<String, Function>();

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

Expand Down
4 changes: 2 additions & 2 deletions lib/core_dom/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class HttpDefaults {
*/
@Injectable()
class Http {
var _pendingRequests = <String, async.Future<HttpResponse>>{};
var _pendingRequests = new HashMap<String, async.Future<HttpResponse>>();
BrowserCookies _cookies;
LocationWrapper _location;
UrlRewriter _rewriter;
Expand Down Expand Up @@ -649,7 +649,7 @@ class Http {
static Map<String, String> parseHeaders(dom.HttpRequest value) {
var headers = value.getAllResponseHeaders();

var parsed = {};
var parsed = new HashMap();

if (headers == null) return parsed;

Expand Down
1 change: 1 addition & 0 deletions lib/core_dom/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import 'package:angular/change_detection/ast_parser.dart';
import 'package:angular/core/registry.dart';

import 'package:angular/directive/module.dart' show NgBaseCss;
import 'dart:collection';

part 'animation.dart';
part 'view.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/core_dom/ng_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class NgElement {
final Scope _scope;
final Animate _animate;

final _classesToUpdate = <String, bool>{};
final _attributesToUpdate = <String, dynamic>{};
final _classesToUpdate = new HashMap<String, bool>();
final _attributesToUpdate = new HashMap<String, dynamic>();

bool _writeScheduled = false;

Expand Down
20 changes: 10 additions & 10 deletions lib/core_dom/selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DirectiveSelector {
ElementBinderBuilder builder = _binderFactory.builder(_formatters, _directives);
List<_ElementSelector> partialSelection;
final classes = new Set<String>();
final attrs = <String, String>{};
final attrs = new HashMap<String, String>();

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

final _elementMap = <String, List<_Directive>>{};
final _elementPartialMap = <String, _ElementSelector>{};
final _elementMap = new HashMap<String, List<_Directive>>();
final _elementPartialMap = new HashMap<String, _ElementSelector>();

final _classMap = <String, List<_Directive>>{};
final _classPartialMap = <String, _ElementSelector>{};
final _classMap = new HashMap<String, List<_Directive>>();
final _classPartialMap = new HashMap<String, _ElementSelector>();

final _attrValueMap = <String, Map<String, List<_Directive>>>{};
final _attrValuePartialMap = <String, Map<String, _ElementSelector>>{};
final _attrValueMap = new HashMap<String, Map<String, List<_Directive>>>();
final _attrValuePartialMap = new HashMap<String, Map<String, _ElementSelector>>();

_ElementSelector(this._name);

Expand All @@ -268,12 +268,12 @@ class _ElementSelector {
}
} else if ((name = part.attrName) != null) {
if (terminal) {
elSelector._attrValueMap.putIfAbsent(name, () => <String, List<_Directive>>{})
elSelector._attrValueMap.putIfAbsent(name, () => new HashMap<String, List<_Directive>>())
.putIfAbsent(part.attrValue, () => [])
.add(directive);
} else {
elSelector = elSelector._attrValuePartialMap
.putIfAbsent(name, () => <String, _ElementSelector>{})
.putIfAbsent(name, () => new HashMap<String, _ElementSelector>())
.putIfAbsent(part.attrValue, () => new _ElementSelector(name));
}
} else {
Expand Down Expand Up @@ -349,7 +349,7 @@ class _ElementSelector {

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

String _matchingKey(Iterable<String> keys, String attrName) =>
keys.firstWhere((key) =>
Expand Down
1 change: 1 addition & 0 deletions lib/directive/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:angular/utils.dart';
import 'package:angular/change_detection/watch_group.dart';
import 'package:angular/change_detection/change_detection.dart';
import 'package:angular/directive/static_keys.dart';
import 'dart:collection';

part 'a_href.dart';
part 'ng_base_css.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/directive/ng_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class NgEvent {
// Is it better to use a map of listeners or have 29 properties on this
// object? One would pretty much only assign to one or two of those
// properties. I'm opting for the map since it's less boilerplate code.
var listeners = {};
var listeners = new HashMap();
final dom.Element element;
final Scope scope;

Expand Down
2 changes: 1 addition & 1 deletion lib/directive/ng_repeat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class NgRepeat {
if (trackByExpr != null) {
Expression trackBy = _parser(trackByExpr);
_generateId = ((key, value, index) {
final context = <String, Object>{}
final context = new HashMap<String, Object>()
..[_valueIdentifier] = value
..[r'$index'] = index
..[r'$id'] = (obj) => obj;
Expand Down
1 change: 1 addition & 0 deletions lib/routing/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ import 'package:angular/core_dom/module_internal.dart';
import 'package:route_hierarchical/client.dart';

import 'package:angular/routing/static_keys.dart';
import 'dart:collection';

part 'routing.dart';
part 'ng_view.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/routing/ng_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class NgView implements DetachAware, RouteProvider {
String get routeName => _viewRoute.name;

Map<String, String> get parameters {
var res = <String, String>{};
var res = new HashMap<String, String>();
var p = _viewRoute;
while (p != null) {
res.addAll(p.parameters);
Expand Down

0 comments on commit 9651c87

Please sign in to comment.