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

Commit 3aedb1a

Browse files
drpicoxgkalpak
authored andcommitted
perf($compile): wrap try/catch of collect comment directives into a function to avoid V8 deopt
Closes #14848
1 parent dcf8aab commit 3aedb1a

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/ng/compile.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -2052,26 +2052,32 @@ 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(node, directives, attrs, maxPriority, ignoreDirective);
20682056
break;
20692057
}
20702058

20712059
directives.sort(byPriority);
20722060
return directives;
20732061
}
20742062

2063+
function collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
2064+
// function created because of performance, try/catch disables
2065+
// the optimization of the whole function #14848
2066+
try {
2067+
var match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
2068+
if (match) {
2069+
var nName = directiveNormalize(match[1]);
2070+
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
2071+
attrs[nName] = trim(match[2]);
2072+
}
2073+
}
2074+
} catch (e) {
2075+
// turns out that under some circumstances IE9 throws errors when one attempts to read
2076+
// comment's node value.
2077+
// Just ignore it and continue. (Can't seem to reproduce in test case.)
2078+
}
2079+
}
2080+
20752081
/**
20762082
* Given a node with an directive-start it collects all of the siblings until it finds
20772083
* directive-end.

0 commit comments

Comments
 (0)