From 606261043295812c8c7e6dab07aad9808003f075 Mon Sep 17 00:00:00 2001 From: James deBoer Date: Thu, 29 May 2014 12:13:22 -0700 Subject: [PATCH] perf(view factory): Remove try-finally from ElementBinder._link This saves 9% of the runtime in the TreeComponent benchmark. --- lib/core_dom/element_binder.dart | 58 +++++++++++++------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/lib/core_dom/element_binder.dart b/lib/core_dom/element_binder.dart index e86727790..1fd490892 100644 --- a/lib/core_dom/element_binder.dart +++ b/lib/core_dom/element_binder.dart @@ -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()); } }); }