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

Commit acd4551

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 a89b6e2 commit acd4551

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
@@ -2065,26 +2065,32 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
20652065
addTextInterpolateDirective(directives, node.nodeValue);
20662066
break;
20672067
case NODE_TYPE_COMMENT: /* Comment */
2068-
try {
2069-
match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
2070-
if (match) {
2071-
nName = directiveNormalize(match[1]);
2072-
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
2073-
attrs[nName] = trim(match[2]);
2074-
}
2075-
}
2076-
} catch (e) {
2077-
// turns out that under some circumstances IE9 throws errors when one attempts to read
2078-
// comment's node value.
2079-
// Just ignore it and continue. (Can't seem to reproduce in test case.)
2080-
}
2068+
collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective);
20812069
break;
20822070
}
20832071

20842072
directives.sort(byPriority);
20852073
return directives;
20862074
}
20872075

2076+
function collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
2077+
// function created because of performance, try/catch disables
2078+
// the optimization of the whole function #14848
2079+
try {
2080+
var match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
2081+
if (match) {
2082+
var nName = directiveNormalize(match[1]);
2083+
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
2084+
attrs[nName] = trim(match[2]);
2085+
}
2086+
}
2087+
} catch (e) {
2088+
// turns out that under some circumstances IE9 throws errors when one attempts to read
2089+
// comment's node value.
2090+
// Just ignore it and continue. (Can't seem to reproduce in test case.)
2091+
}
2092+
}
2093+
20882094
/**
20892095
* Given a node with an directive-start it collects all of the siblings until it finds
20902096
* directive-end.

0 commit comments

Comments
 (0)