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

Commit 3a40bd4

Browse files
committed
perf($compile): wrap try/catch of collect comment directives into a function to avoid V8 deopt
1 parent f7405e3 commit 3a40bd4

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/ng/compile.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,24 +2052,30 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
20522052
addTextInterpolateDirective(directives, node.nodeValue);
20532053
break;
20542054
case NODE_TYPE_COMMENT: /* Comment */
2055-
try {
2056-
match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
2057-
if (match) {
2058-
nName = directiveNormalize(match[1]);
2059-
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
2060-
attrs[nName] = trim(match[2]);
2061-
}
2062-
}
2063-
} catch (e) {
2064-
// turns out that under some circumstances IE9 throws errors when one attempts to read
2065-
// comment's node value.
2066-
// Just ignore it and continue. (Can't seem to reproduce in test case.)
2067-
}
2055+
collectCommentDirectives();
20682056
break;
20692057
}
20702058

20712059
directives.sort(byPriority);
20722060
return directives;
2061+
2062+
function collectCommentDirectives() {
2063+
// function created because of performance, try/catch disables
2064+
// the optimization of the whole function #14848
2065+
try {
2066+
match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
2067+
if (match) {
2068+
nName = directiveNormalize(match[1]);
2069+
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
2070+
attrs[nName] = trim(match[2]);
2071+
}
2072+
}
2073+
} catch (e) {
2074+
// turns out that under some circumstances IE9 throws errors when one attempts to read
2075+
// comment's node value.
2076+
// Just ignore it and continue. (Can't seem to reproduce in test case.)
2077+
}
2078+
}
20732079
}
20742080

20752081
/**

0 commit comments

Comments
 (0)