Bug 1312331 - Build up list of applicable rules in reverse to avoid quadratic time array manipulations. r=erahm

MozReview-Commit-ID: HAjtxQVZo8X
This commit is contained in:
Cameron McCormack 2016-10-24 02:59:00 +02:00
Родитель aec865dde5
Коммит 6e3f0feaaa
1 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -247,8 +247,14 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement,
return NS_OK;
}
AutoTArray<nsRuleNode*, 16> ruleNodes;
while (!ruleNode->IsRoot()) {
ruleNodes.AppendElement(ruleNode);
ruleNode = ruleNode->GetParent();
}
nsCOMPtr<nsIMutableArray> rules = nsArray::Create();
for ( ; !ruleNode->IsRoot(); ruleNode = ruleNode->GetParent()) {
for (nsRuleNode* ruleNode : Reversed(ruleNodes)) {
RefPtr<Declaration> decl = do_QueryObject(ruleNode->GetRule());
if (decl) {
RefPtr<mozilla::css::StyleRule> styleRule =
@ -256,7 +262,7 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement,
if (styleRule) {
nsCOMPtr<nsIDOMCSSRule> domRule = styleRule->GetDOMRule();
if (domRule) {
rules->InsertElementAt(domRule, 0, /*weak =*/ false);
rules->AppendElement(domRule, /*weak =*/ false);
}
}
}