Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 35134a0

Browse files
committed
perf($compile): optimize nodeLinkFn
Functions with try/catch block can't be optimized, so we can move the try/catch block into a tiny fn and make it possible for the complex nodeLinkFn to get optimized.
1 parent 8d933bf commit 35134a0

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/ng/compile.js

+25-14
Original file line numberDiff line numberDiff line change
@@ -1589,13 +1589,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15891589

15901590
// PRELINKING
15911591
for(i = 0, ii = preLinkFns.length; i < ii; i++) {
1592-
try {
1593-
linkFn = preLinkFns[i];
1594-
linkFn(linkFn.isolateScope ? isolateScope : scope, $element, attrs,
1595-
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers), transcludeFn);
1596-
} catch (e) {
1597-
$exceptionHandler(e, startingTag($element));
1598-
}
1592+
linkFn = preLinkFns[i];
1593+
invokeLinkFn(linkFn,
1594+
linkFn.isolateScope ? isolateScope : scope,
1595+
$element,
1596+
attrs,
1597+
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
1598+
transcludeFn
1599+
);
15991600
}
16001601

16011602
// RECURSION
@@ -1609,13 +1610,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
16091610

16101611
// POSTLINKING
16111612
for(i = postLinkFns.length - 1; i >= 0; i--) {
1612-
try {
1613-
linkFn = postLinkFns[i];
1614-
linkFn(linkFn.isolateScope ? isolateScope : scope, $element, attrs,
1615-
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers), transcludeFn);
1616-
} catch (e) {
1617-
$exceptionHandler(e, startingTag($element));
1618-
}
1613+
linkFn = postLinkFns[i];
1614+
invokeLinkFn(linkFn,
1615+
linkFn.isolateScope ? isolateScope : scope,
1616+
$element,
1617+
attrs,
1618+
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
1619+
transcludeFn
1620+
);
16191621
}
16201622

16211623
// This is the function that is injected as `$transclude`.
@@ -2076,6 +2078,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
20762078
function cloneAndAnnotateFn(fn, annotation) {
20772079
return extend(function() { return fn.apply(null, arguments); }, fn, annotation);
20782080
}
2081+
2082+
2083+
function invokeLinkFn(linkFn, scope, $element, attrs, controllers, transcludeFn) {
2084+
try {
2085+
linkFn(scope, $element, attrs, controllers, transcludeFn);
2086+
} catch(e) {
2087+
$exceptionHandler(e, startingTag($element));
2088+
}
2089+
}
20792090
}];
20802091
}
20812092

0 commit comments

Comments
 (0)