From aee2d80f628ba02d0561c921b7bb1939b3480fca Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 23 Jan 2017 15:39:01 -0500 Subject: Cleanup memory in CFDE_CSSRuleCollection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl cleans up the memory for the CFDE_CSSRuleCollection::Data parameter. Change-Id: I449ffdeebdc6463bf68b991fffecdc6cf0b25362 Reviewed-on: https://pdfium-review.googlesource.com/2296 Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- xfa/fde/css/cfde_cssstyleselector.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'xfa/fde/css/cfde_cssstyleselector.cpp') diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp index b7275fca93..63d8e0986b 100644 --- a/xfa/fde/css/cfde_cssstyleselector.cpp +++ b/xfa/fde/css/cfde_cssstyleselector.cpp @@ -85,27 +85,30 @@ int32_t CFDE_CSSStyleSelector::MatchDeclarations( if (m_UARules.CountSelectors() == 0) return 0; - if (pCache->HashTag()) - MatchRules(pCache, m_UARules.GetTagRuleData(pCache->HashTag())); - - std::sort(m_MatchedRules.begin(), m_MatchedRules.end(), - [](const CFDE_CSSRuleCollection::Data* p1, - const CFDE_CSSRuleCollection::Data* p2) { - return p1->dwPriority < p2->dwPriority; - }); - for (const auto& rule : m_MatchedRules) + // The ::Data is owned by the m_RuleCollection. + std::vector matchedRules; + + if (pCache->HashTag()) { + MatchRules(&matchedRules, pCache, + m_UARules.GetTagRuleData(pCache->HashTag())); + } + + for (const auto& rule : matchedRules) matchedDecls.Add(rule->pDeclaration); - m_MatchedRules.clear(); return matchedDecls.GetSize(); } -void CFDE_CSSStyleSelector::MatchRules(CFDE_CSSTagCache* pCache, - CFDE_CSSRuleCollection::Data* pList) { - while (pList) { - if (MatchSelector(pCache, pList->pSelector)) - m_MatchedRules.push_back(pList); - pList = pList->pNext; +void CFDE_CSSStyleSelector::MatchRules( + std::vector* matchedRules, + CFDE_CSSTagCache* pCache, + const std::vector>* pList) { + if (!pList) + return; + + for (const auto& d : *pList) { + if (MatchSelector(pCache, d->pSelector)) + matchedRules->push_back(d.get()); } } -- cgit v1.2.3