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

Commit

Permalink
perf(view factory): Remove try-finally from ElementBinder._link
Browse files Browse the repository at this point in the history
This saves 9% of the runtime in the TreeComponent benchmark.
  • Loading branch information
jbdeboer authored and [email protected] committed May 29, 2014
1 parent 9f4defe commit 6062610
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions lib/core_dom/element_binder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,46 +203,36 @@ class ElementBinder {

void _link(nodeInjector, probe, scope, nodeAttrs, formatters) {
_usableDirectiveRefs.forEach((DirectiveRef ref) {
var linkTimer;
try {
var linkMapTimer;
assert((linkTimer = _perf.startTimer('ng.view.link', ref.type)) != false);
var directive = nodeInjector.get(ref.type);
probe.directives.add(directive);
assert((linkMapTimer = _perf.startTimer('ng.view.link.map', ref.type)) != false);

if (ref.annotation is Controller) {
scope.context[(ref.annotation as Controller).publishAs] = directive;
}
var directive = nodeInjector.get(ref.type);
probe.directives.add(directive);

var tasks = new _TaskList(directive is AttachAware ? () {
if (scope.isAttached) directive.attach();
} : null);
if (ref.annotation is Controller) {
scope.context[(ref.annotation as Controller).publishAs] = directive;
}

if (ref.mappings.isNotEmpty) {
if (nodeAttrs == null) nodeAttrs = new _AnchorAttrs(ref);
_createAttrMappings(directive, scope, ref.mappings, nodeAttrs, formatters, tasks);
}
var tasks = new _TaskList(directive is AttachAware ? () {
if (scope.isAttached) directive.attach();
} : null);

if (directive is AttachAware) {
var taskId = tasks.registerTask();
Watch watch;
watch = scope.watch('1', // Cheat a bit.
(_, __) {
watch.remove();
tasks.completeTask(taskId);
});
}
if (ref.mappings.isNotEmpty) {
if (nodeAttrs == null) nodeAttrs = new _AnchorAttrs(ref);
_createAttrMappings(directive, scope, ref.mappings, nodeAttrs, formatters, tasks);
}

tasks.doneRegistering();
if (directive is AttachAware) {
var taskId = tasks.registerTask();
Watch watch;
watch = scope.watch('1', // Cheat a bit.
(_, __) {
watch.remove();
tasks.completeTask(taskId);
});
}

if (directive is DetachAware) {
scope.on(ScopeEvent.DESTROY).listen((_) => directive.detach());
}
tasks.doneRegistering();

assert(_perf.stopTimer(linkMapTimer) != false);
} finally {
assert(_perf.stopTimer(linkTimer) != false);
if (directive is DetachAware) {
scope.on(ScopeEvent.DESTROY).listen((_) => directive.detach());
}
});
}
Expand Down

0 comments on commit 6062610

Please sign in to comment.