From 6e3f0feaaaf60957714d40c46f48941e59cf1e32 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Mon, 24 Oct 2016 02:59:00 +0200 Subject: [PATCH] Bug 1312331 - Build up list of applicable rules in reverse to avoid quadratic time array manipulations. r=erahm MozReview-Commit-ID: HAjtxQVZo8X --- layout/inspector/inDOMUtils.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index adc1525b2899..9f1dcaad3fc8 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -247,8 +247,14 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement, return NS_OK; } + AutoTArray ruleNodes; + while (!ruleNode->IsRoot()) { + ruleNodes.AppendElement(ruleNode); + ruleNode = ruleNode->GetParent(); + } + nsCOMPtr rules = nsArray::Create(); - for ( ; !ruleNode->IsRoot(); ruleNode = ruleNode->GetParent()) { + for (nsRuleNode* ruleNode : Reversed(ruleNodes)) { RefPtr decl = do_QueryObject(ruleNode->GetRule()); if (decl) { RefPtr styleRule = @@ -256,7 +262,7 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement, if (styleRule) { nsCOMPtr domRule = styleRule->GetDOMRule(); if (domRule) { - rules->InsertElementAt(domRule, 0, /*weak =*/ false); + rules->AppendElement(domRule, /*weak =*/ false); } } }