summaryrefslogtreecommitdiff
path: root/xfa/fde/css/cfde_cssrulecollection.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-01-23 15:39:01 -0500
committerChromium commit bot <commit-bot@chromium.org>2017-01-24 14:47:55 +0000
commitaee2d80f628ba02d0561c921b7bb1939b3480fca (patch)
tree15e3c3060fe9f7ef069ce901d371051212a0e4ab /xfa/fde/css/cfde_cssrulecollection.cpp
parent1339133720c3b8bce77e970b479ec179160f30b5 (diff)
downloadpdfium-aee2d80f628ba02d0561c921b7bb1939b3480fca.tar.xz
Cleanup memory in CFDE_CSSRuleCollection
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 <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fde/css/cfde_cssrulecollection.cpp')
-rw-r--r--xfa/fde/css/cfde_cssrulecollection.cpp62
1 files changed, 17 insertions, 45 deletions
diff --git a/xfa/fde/css/cfde_cssrulecollection.cpp b/xfa/fde/css/cfde_cssrulecollection.cpp
index c140c8e682..a72e1bb0bd 100644
--- a/xfa/fde/css/cfde_cssrulecollection.cpp
+++ b/xfa/fde/css/cfde_cssrulecollection.cpp
@@ -7,9 +7,9 @@
#include "xfa/fde/css/cfde_cssrulecollection.h"
#include <algorithm>
-#include <map>
-#include <memory>
+#include <utility>
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/css/cfde_cssdeclaration.h"
#include "xfa/fde/css/cfde_cssselector.h"
#include "xfa/fde/css/cfde_cssstylerule.h"
@@ -17,15 +17,21 @@
#include "xfa/fde/css/cfde_csssyntaxparser.h"
#include "xfa/fde/css/cfde_csstagcache.h"
+CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() : m_iSelectors(0) {}
+
+CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
+ Clear();
+}
+
void CFDE_CSSRuleCollection::Clear() {
m_TagRules.clear();
m_iSelectors = 0;
}
-CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() : m_iSelectors(0) {}
-
-CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
- Clear();
+const std::vector<std::unique_ptr<CFDE_CSSRuleCollection::Data>>*
+CFDE_CSSRuleCollection::GetTagRuleData(uint32_t dwTagHash) const {
+ auto it = m_TagRules.find(dwTagHash);
+ return it != m_TagRules.end() ? &it->second : nullptr;
}
void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* sheet,
@@ -42,46 +48,12 @@ void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheet* pStyleSheet,
int32_t iSelectors = pStyleRule->CountSelectorLists();
for (int32_t i = 0; i < iSelectors; ++i) {
CFDE_CSSSelector* pSelector = pStyleRule->GetSelectorList(i);
- AddRuleTo(&m_TagRules, pSelector->GetNameHash(), pSelector, pDeclaration);
+ m_TagRules[pSelector->GetNameHash()].push_back(
+ pdfium::MakeUnique<Data>(pSelector, pDeclaration));
+ m_iSelectors++;
}
}
-void CFDE_CSSRuleCollection::AddRuleTo(std::map<uint32_t, Data*>* pMap,
- uint32_t dwKey,
- CFDE_CSSSelector* pSel,
- CFDE_CSSDeclaration* pDecl) {
- Data* pData = NewRuleData(pSel, pDecl);
- Data* pList = (*pMap)[dwKey];
- if (!pList) {
- (*pMap)[dwKey] = pData;
- } else if (AddRuleTo(&pList, pData)) {
- (*pMap)[dwKey] = pList;
- }
-}
-
-bool CFDE_CSSRuleCollection::AddRuleTo(Data** pList, Data* pData) {
- if (*pList) {
- pData->pNext = (*pList)->pNext;
- (*pList)->pNext = pData;
- return false;
- }
- *pList = pData;
- return true;
-}
-
-CFDE_CSSRuleCollection::Data* CFDE_CSSRuleCollection::NewRuleData(
- CFDE_CSSSelector* pSel,
- CFDE_CSSDeclaration* pDecl) {
- return new Data(pSel, pDecl, ++m_iSelectors);
-}
-
CFDE_CSSRuleCollection::Data::Data(CFDE_CSSSelector* pSel,
- CFDE_CSSDeclaration* pDecl,
- uint32_t dwPos)
- : pSelector(pSel), pDeclaration(pDecl), dwPriority(dwPos), pNext(nullptr) {
- static const uint32_t s_Specific[5] = {0x00010000, 0x00010000, 0x00100000,
- 0x00100000, 0x01000000};
- for (; pSel; pSel = pSel->GetNextSelector()) {
- dwPriority += s_Specific[static_cast<int>(pSel->GetType())];
- }
-}
+ CFDE_CSSDeclaration* pDecl)
+ : pSelector(pSel), pDeclaration(pDecl) {}