summaryrefslogtreecommitdiff
path: root/xfa/src/fdp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2016-02-23 16:06:43 -0800
committerLei Zhang <thestig@chromium.org>2016-02-23 16:06:43 -0800
commita7f70cc1ff7d54b92d9c55326c1439a25116e00c (patch)
treef2c283e244c6f614c39b8e7fa7f81505cd9d4a3a /xfa/src/fdp
parentd9aba86443b32b686cf25b5465bbcaad9f04c308 (diff)
downloadpdfium-a7f70cc1ff7d54b92d9c55326c1439a25116e00c.tar.xz
Simplify CFDE_CSSStyleSelector::SortRulesTo().
Also remove another CFX_ArrayTemplate usage. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1730753002 .
Diffstat (limited to 'xfa/src/fdp')
-rw-r--r--xfa/src/fdp/src/css/fde_cssstyleselector.cpp62
-rw-r--r--xfa/src/fdp/src/css/fde_cssstyleselector.h6
2 files changed, 31 insertions, 37 deletions
diff --git a/xfa/src/fdp/src/css/fde_cssstyleselector.cpp b/xfa/src/fdp/src/css/fde_cssstyleselector.cpp
index 6d05065e7d..f51d7418d9 100644
--- a/xfa/src/fdp/src/css/fde_cssstyleselector.cpp
+++ b/xfa/src/fdp/src/css/fde_cssstyleselector.cpp
@@ -8,6 +8,7 @@
#include "xfa/src/fdp/src/css/fde_cssdeclaration.h"
#include "xfa/src/fdp/src/css/fde_cssstyleselector.h"
#include "xfa/src/foxitlib.h"
+
int32_t CFDE_CSSCounterStyle::FindIndex(const FX_WCHAR* pszIdentifier) {
int32_t iCount = m_arrCounterData.GetSize();
for (int32_t i = 0; i < iCount; i++) {
@@ -188,23 +189,26 @@ void CFDE_CSSRuleCollection::AddRuleTo(CFX_MapPtrToPtr& map,
map.SetAt(pKey, pList);
}
}
-inline FX_BOOL CFDE_CSSRuleCollection::AddRuleTo(FDE_CSSRULEDATA*& pList,
- FDE_CSSRULEDATA* pData) {
- if (pList == NULL) {
- pList = pData;
- return TRUE;
- } else {
+
+FX_BOOL CFDE_CSSRuleCollection::AddRuleTo(FDE_CSSRULEDATA*& pList,
+ FDE_CSSRULEDATA* pData) {
+ if (pList) {
pData->pNext = pList->pNext;
pList->pNext = pData;
return FALSE;
}
+
+ pList = pData;
+ return TRUE;
}
-inline FDE_CSSRULEDATA* CFDE_CSSRuleCollection::NewRuleData(
+
+FDE_CSSRULEDATA* CFDE_CSSRuleCollection::NewRuleData(
IFDE_CSSSelector* pSel,
IFDE_CSSDeclaration* pDecl) {
return FDE_NewWith(m_pStaticStore)
FDE_CSSRULEDATA(pSel, pDecl, ++m_iSelectors);
}
+
IFDE_CSSStyleSelector* IFDE_CSSStyleSelector::Create() {
return new CFDE_CSSStyleSelector;
}
@@ -341,23 +345,28 @@ int32_t CFDE_CSSStyleSelector::MatchDeclarations(
} else {
MatchRules(pCache, rules.GetPersudoRuleData(), ePersudoType);
}
- if (m_MatchedRules.GetSize() > 0) {
- SortRulesTo(matchedDecls);
- m_MatchedRules.RemoveAt(0, m_MatchedRules.GetSize());
- }
+
+ std::sort(m_MatchedRules.begin(), m_MatchedRules.end(),
+ [](const FDE_CSSRULEDATA* p1, const FDE_CSSRULEDATA* p2) {
+ return p1->dwPriority < p2->dwPriority;
+ });
+ for (const auto& rule : m_MatchedRules)
+ matchedDecls.Add(rule->pDeclaration);
+ m_MatchedRules.clear();
}
return matchedDecls.GetSize();
}
-inline void CFDE_CSSStyleSelector::MatchRules(FDE_CSSTAGCACHE* pCache,
- FDE_CSSRULEDATA* pList,
- FDE_CSSPERSUDO ePersudoType) {
- while (pList != NULL) {
- if (MatchSelector(pCache, pList->pSelector, ePersudoType)) {
- m_MatchedRules.Add(pList);
- }
+
+void CFDE_CSSStyleSelector::MatchRules(FDE_CSSTAGCACHE* pCache,
+ FDE_CSSRULEDATA* pList,
+ FDE_CSSPERSUDO ePersudoType) {
+ while (pList) {
+ if (MatchSelector(pCache, pList->pSelector, ePersudoType))
+ m_MatchedRules.push_back(pList);
pList = pList->pNext;
}
}
+
FX_BOOL CFDE_CSSStyleSelector::MatchSelector(FDE_CSSTAGCACHE* pCache,
IFDE_CSSSelector* pSel,
FDE_CSSPERSUDO ePersudoType) {
@@ -407,22 +416,7 @@ FX_BOOL CFDE_CSSStyleSelector::MatchSelector(FDE_CSSTAGCACHE* pCache,
}
return pSel == NULL && pCache != NULL;
}
-void CFDE_CSSStyleSelector::SortRulesTo(CFDE_CSSDeclarationArray& matchDecls) {
- for (int32_t j = m_MatchedRules.GetUpperBound(); j >= 0; --j) {
- FDE_CSSRULEDATA*& pMin = m_MatchedRules.ElementAt(j);
- FX_DWORD dwMin = pMin->dwPriority;
- for (int32_t i = j - 1; i >= 0; --i) {
- FDE_CSSRULEDATA*& pCur = m_MatchedRules.ElementAt(i);
- if (dwMin > pCur->dwPriority) {
- dwMin = pCur->dwPriority;
- FDE_CSSRULEDATA* p = pMin;
- pMin = pCur;
- pCur = p;
- }
- }
- matchDecls.Add(pMin->pDeclaration);
- }
-}
+
void CFDE_CSSStyleSelector::ComputeStyle(
IFDE_CSSTagProvider* pTag,
const IFDE_CSSDeclaration** ppDeclArray,
diff --git a/xfa/src/fdp/src/css/fde_cssstyleselector.h b/xfa/src/fdp/src/css/fde_cssstyleselector.h
index f2547136ea..d1ae0f2979 100644
--- a/xfa/src/fdp/src/css/fde_cssstyleselector.h
+++ b/xfa/src/fdp/src/css/fde_cssstyleselector.h
@@ -7,6 +7,8 @@
#ifndef XFA_SRC_FDP_SRC_CSS_FDE_CSSSTYLESELECTOR_H_
#define XFA_SRC_FDP_SRC_CSS_FDE_CSSSTYLESELECTOR_H_
+#include <vector>
+
#include "xfa/src/fdp/include/fde_mem.h"
#include "xfa/src/fgas/include/fx_sys.h"
@@ -23,7 +25,6 @@ struct FDE_CSSRULEDATA : public CFX_Target {
FX_DWORD dwPriority;
FDE_CSSRULEDATA* pNext;
};
-typedef CFX_ArrayTemplate<FDE_CSSRULEDATA*> CFDE_CSSRuleDataArray;
class CFDE_CSSRuleCollection : public CFX_Target {
public:
@@ -115,7 +116,6 @@ class CFDE_CSSStyleSelector : public IFDE_CSSStyleSelector, public CFX_Target {
void MatchRules(FDE_CSSTAGCACHE* pCache,
FDE_CSSRULEDATA* pList,
FDE_CSSPERSUDO ePersudoType);
- void SortRulesTo(CFDE_CSSDeclarationArray& matchDecls);
FX_BOOL MatchSelector(FDE_CSSTAGCACHE* pCache,
IFDE_CSSSelector* pSel,
FDE_CSSPERSUDO ePersudoType);
@@ -181,7 +181,7 @@ class CFDE_CSSStyleSelector : public IFDE_CSSStyleSelector, public CFX_Target {
IFX_MEMAllocator* m_pInlineStyleStore;
IFX_MEMAllocator* m_pFixedStyleStore;
CFDE_CSSAccelerator* m_pAccelerator;
- CFDE_CSSRuleDataArray m_MatchedRules;
+ std::vector<FDE_CSSRULEDATA*> m_MatchedRules;
};
struct FDE_CSSCOUNTERDATA {