perf($compile): wrap try/catch of collect comment directives into a function to avoid V8 deopt

Closes #14848
This commit is contained in:
David Rodenas Pico
2016-06-30 09:52:04 +02:00
committed by Georgios Kalpakas
parent dcf8aab85d
commit 3aedb1a70d
+19 -13
View File
@@ -2052,19 +2052,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
addTextInterpolateDirective(directives, node.nodeValue);
break;
case NODE_TYPE_COMMENT: /* Comment */
try {
match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
if (match) {
nName = directiveNormalize(match[1]);
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
attrs[nName] = trim(match[2]);
}
}
} catch (e) {
// turns out that under some circumstances IE9 throws errors when one attempts to read
// comment's node value.
// Just ignore it and continue. (Can't seem to reproduce in test case.)
}
collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective);
break;
}
@@ -2072,6 +2060,24 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return directives;
}
function collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
// function created because of performance, try/catch disables
// the optimization of the whole function #14848
try {
var match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
if (match) {
var nName = directiveNormalize(match[1]);
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
attrs[nName] = trim(match[2]);
}
}
} catch (e) {
// turns out that under some circumstances IE9 throws errors when one attempts to read
// comment's node value.
// Just ignore it and continue. (Can't seem to reproduce in test case.)
}
}
/**
* Given a node with an directive-start it collects all of the siblings until it finds
* directive-end.