summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-04-14 11:04:57 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-14 11:04:57 -0700
commit7b1ccf9697692844e764d730079a0f0b98fd6d06 (patch)
tree8e1c0b669a8dd1e06de50454b4e5db5e7c6e1a2a /core/fpdfdoc
parent774bdde253b8394aa2ac791e273508ff006d813a (diff)
downloadpdfium-7b1ccf9697692844e764d730079a0f0b98fd6d06.tar.xz
Make CPDF_Dictionary methods take CFX_ByteString arguments
This will help avoid duplicate allocation of CFX_ByteStrings when the caller already has one. It may seem counter-intuitive that requiring the caller to pass an allocated CFX_ByteString rather than a static CFX_ByteStringC would improve the situation, but due to the idiosyncrasies of std::map, the CPDF_Dictionary methods must always do an allocation under the covers which can't be avoided. The changed callers in this CL are places where we would previously demote to CFX_ByteStringC and then allocate a a duplicate CFX_ByteString in the dictionary method. Review URL: https://codereview.chromium.org/1889863002
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpvt_fontmap.cpp5
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp16
-rw-r--r--core/fpdfdoc/doc_annot.cpp4
-rw-r--r--core/fpdfdoc/doc_basic.cpp2
-rw-r--r--core/fpdfdoc/doc_form.cpp2
-rw-r--r--core/fpdfdoc/doc_formcontrol.cpp6
-rw-r--r--core/fpdfdoc/doc_formfield.cpp6
-rw-r--r--core/fpdfdoc/doc_ocg.cpp8
-rw-r--r--core/fpdfdoc/doc_tagged.cpp7
-rw-r--r--core/fpdfdoc/doc_utils.cpp9
10 files changed, 30 insertions, 35 deletions
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index a0919ed084..d4171bd147 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -38,9 +38,8 @@ void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
return;
if (CPDF_Dictionary* pFontList = pResDict->GetDictBy("Font")) {
- if (!pFontList->KeyExist(sSysFontAlias.AsStringC()))
- pFontList->SetAtReference(sSysFontAlias.AsStringC(), pDoc,
- pPDFFont->GetFontDict());
+ if (!pFontList->KeyExist(sSysFontAlias))
+ pFontList->SetAtReference(sSysFontAlias, pDoc, pPDFFont->GetFontDict());
}
pSysFont = pPDFFont;
}
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 3c2b47c275..06a64359e9 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -54,12 +54,12 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
}
CPDF_Dictionary* pDRFontDict = pDRDict ? pDRDict->GetDictBy("Font") : nullptr;
if (pDRFontDict) {
- pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1).AsStringC());
+ pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1));
if (!pFontDict && !bUseFormRes) {
pDRDict = pFormDict->GetDictBy("DR");
pDRFontDict = pDRDict->GetDictBy("Font");
if (pDRFontDict)
- pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1).AsStringC());
+ pFontDict = pDRFontDict->GetDictBy(sFontName.Mid(1));
}
}
if (!pDRFontDict)
@@ -72,7 +72,7 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
pFontDict->SetAtName("BaseFont", "Helvetica");
pFontDict->SetAtName("Encoding", "WinAnsiEncoding");
pDoc->AddIndirectObject(pFontDict);
- pDRFontDict->SetAtReference(sFontName.Mid(1).AsStringC(), pDoc, pFontDict);
+ pDRFontDict->SetAtReference(sFontName.Mid(1), pDoc, pFontDict);
}
CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
if (!pDefFont)
@@ -189,9 +189,8 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
pStreamResFontList = new CPDF_Dictionary;
pStreamResList->SetAt("Font", pStreamResFontList);
}
- if (!pStreamResFontList->KeyExist(sFontName.AsStringC()))
- pStreamResFontList->SetAtReference(sFontName.AsStringC(), pDoc,
- pFontDict);
+ if (!pStreamResFontList->KeyExist(sFontName))
+ pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
} else {
pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone());
pStreamResList = pStreamDict->GetDictBy("Resources");
@@ -437,9 +436,8 @@ FX_BOOL GenerateWidgetAP(CPDF_Document* pDoc,
pStreamResFontList = new CPDF_Dictionary;
pStreamResList->SetAt("Font", pStreamResFontList);
}
- if (!pStreamResFontList->KeyExist(sFontName.AsStringC()))
- pStreamResFontList->SetAtReference(sFontName.AsStringC(), pDoc,
- pFontDict);
+ if (!pStreamResFontList->KeyExist(sFontName))
+ pStreamResFontList->SetAtReference(sFontName, pDoc, pFontDict);
} else {
pStreamDict->SetAt("Resources", pFormDict->GetDictBy("DR")->Clone());
pStreamResList = pStreamDict->GetDictBy("Resources");
diff --git a/core/fpdfdoc/doc_annot.cpp b/core/fpdfdoc/doc_annot.cpp
index 3b90b0b4b5..42d4a665fe 100644
--- a/core/fpdfdoc/doc_annot.cpp
+++ b/core/fpdfdoc/doc_annot.cpp
@@ -183,12 +183,12 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
CPDF_Dictionary* pDict = pAnnotDict->GetDictBy("Parent");
value = pDict ? pDict->GetStringBy("V") : CFX_ByteString();
}
- if (value.IsEmpty() || !pDict->KeyExist(value.AsStringC()))
+ if (value.IsEmpty() || !pDict->KeyExist(value))
as = "Off";
else
as = value;
}
- return pDict->GetStreamBy(as.AsStringC());
+ return pDict->GetStreamBy(as);
}
return nullptr;
}
diff --git a/core/fpdfdoc/doc_basic.cpp b/core/fpdfdoc/doc_basic.cpp
index 6d6e5c234f..a3e94cb033 100644
--- a/core/fpdfdoc/doc_basic.cpp
+++ b/core/fpdfdoc/doc_basic.cpp
@@ -482,7 +482,7 @@ CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const {
if (pLabel->KeyExist("P")) {
wsLabel += pLabel->GetUnicodeTextBy("P");
}
- CFX_ByteString bsNumberingStyle = pLabel->GetStringBy("S", NULL);
+ CFX_ByteString bsNumberingStyle = pLabel->GetStringBy("S", nullptr);
int nLabelNum = nPage - n + pLabel->GetIntegerBy("St", 1);
CFX_WideString wsNumPortion =
_GetLabelNumPortion(nLabelNum, bsNumberingStyle);
diff --git a/core/fpdfdoc/doc_form.cpp b/core/fpdfdoc/doc_form.cpp
index 6ca40fdaf6..5062b45452 100644
--- a/core/fpdfdoc/doc_form.cpp
+++ b/core/fpdfdoc/doc_form.cpp
@@ -343,7 +343,7 @@ CFX_ByteString CPDF_InterForm::GenerateNewResourceName(
CFX_ByteString bsNum;
while (TRUE) {
CFX_ByteString csKey = csTmp + bsNum;
- if (!pDict->KeyExist(csKey.AsStringC())) {
+ if (!pDict->KeyExist(csKey)) {
return csKey;
}
if (m < iCount) {
diff --git a/core/fpdfdoc/doc_formcontrol.cpp b/core/fpdfdoc/doc_formcontrol.cpp
index b187ea7999..b833f89c17 100644
--- a/core/fpdfdoc/doc_formcontrol.cpp
+++ b/core/fpdfdoc/doc_formcontrol.cpp
@@ -78,7 +78,7 @@ void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) {
continue;
}
if (csKey2 != "Off") {
- pSubDict->ReplaceKey(csKey2.AsStringC(), csValue.AsStringC());
+ pSubDict->ReplaceKey(csKey2, csValue);
break;
}
}
@@ -286,7 +286,7 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() {
if (CPDF_Dictionary* pDict = ToDictionary(pObj)) {
CPDF_Dictionary* pFonts = pDict->GetDictBy("Font");
if (pFonts) {
- CPDF_Dictionary* pElement = pFonts->GetDictBy(csFontNameTag.AsStringC());
+ CPDF_Dictionary* pElement = pFonts->GetDictBy(csFontNameTag);
if (pElement) {
CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement);
if (pFont) {
@@ -303,7 +303,7 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() {
if (CPDF_Dictionary* pDict = ToDictionary(pObj)) {
CPDF_Dictionary* pFonts = pDict->GetDictBy("Font");
if (pFonts) {
- CPDF_Dictionary* pElement = pFonts->GetDictBy(csFontNameTag.AsStringC());
+ CPDF_Dictionary* pElement = pFonts->GetDictBy(csFontNameTag);
if (pElement) {
CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement);
if (pFont) {
diff --git a/core/fpdfdoc/doc_formfield.cpp b/core/fpdfdoc/doc_formfield.cpp
index 7f0ff8716b..d9333eef90 100644
--- a/core/fpdfdoc/doc_formfield.cpp
+++ b/core/fpdfdoc/doc_formfield.cpp
@@ -1065,11 +1065,11 @@ void CPDF_FormField::LoadDA() {
CFX_ByteString font_name = syntax.GetWord();
CPDF_Dictionary* pFontDict = NULL;
if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDictBy("DR") &&
- m_pForm->m_pFormDict->GetDictBy("DR")->GetDictBy("Font"))
+ m_pForm->m_pFormDict->GetDictBy("DR")->GetDictBy("Font")) {
pFontDict = m_pForm->m_pFormDict->GetDictBy("DR")
->GetDictBy("Font")
- ->GetDictBy(font_name.AsStringC());
-
+ ->GetDictBy(font_name);
+ }
if (!pFontDict) {
return;
}
diff --git a/core/fpdfdoc/doc_ocg.cpp b/core/fpdfdoc/doc_ocg.cpp
index b4fb3e1c01..bea3c2ce33 100644
--- a/core/fpdfdoc/doc_ocg.cpp
+++ b/core/fpdfdoc/doc_ocg.cpp
@@ -138,7 +138,7 @@ FX_BOOL CPDF_OCContext::LoadOCGStateFromConfig(const CFX_ByteStringC& csConfig,
if (!pState) {
continue;
}
- bState = pState->GetStringBy(csFind.AsStringC()) != "OFF";
+ bState = pState->GetStringBy(csFind) != "OFF";
}
}
return bState;
@@ -150,11 +150,11 @@ FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary* pOCGDict) const {
CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType);
CPDF_Dictionary* pUsage = pOCGDict->GetDictBy("Usage");
if (pUsage) {
- CPDF_Dictionary* pState = pUsage->GetDictBy(csState.AsStringC());
+ CPDF_Dictionary* pState = pUsage->GetDictBy(csState);
if (pState) {
CFX_ByteString csFind = csState + "State";
- if (pState->KeyExist(csFind.AsStringC())) {
- return pState->GetStringBy(csFind.AsStringC()) != "OFF";
+ if (pState->KeyExist(csFind)) {
+ return pState->GetStringBy(csFind) != "OFF";
}
}
if (csState != "View") {
diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp
index b60c83932e..f559c0ac2b 100644
--- a/core/fpdfdoc/doc_tagged.cpp
+++ b/core/fpdfdoc/doc_tagged.cpp
@@ -205,7 +205,7 @@ CPDF_StructElementImpl::CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree,
m_pDict = pDict;
m_Type = pDict->GetStringBy("S");
if (pTree->m_pRoleMap) {
- CFX_ByteString mapped = pTree->m_pRoleMap->GetStringBy(m_Type.AsStringC());
+ CFX_ByteString mapped = pTree->m_pRoleMap->GetStringBy(m_Type);
if (!mapped.IsEmpty()) {
m_Type = mapped;
}
@@ -373,15 +373,14 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner,
if (CPDF_Array* pArray = pC->AsArray()) {
for (uint32_t i = 0; i < pArray->GetCount(); i++) {
CFX_ByteString class_name = pArray->GetStringAt(i);
- CPDF_Dictionary* pClassDict =
- pClassMap->GetDictBy(class_name.AsStringC());
+ CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name);
if (pClassDict && pClassDict->GetStringBy("O") == owner)
return pClassDict->GetDirectObjectBy(name);
}
return nullptr;
}
CFX_ByteString class_name = pC->GetString();
- CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name.AsStringC());
+ CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name);
if (pClassDict && pClassDict->GetStringBy("O") == owner)
return pClassDict->GetDirectObjectBy(name);
return nullptr;
diff --git a/core/fpdfdoc/doc_utils.cpp b/core/fpdfdoc/doc_utils.cpp
index 2df7d97e31..ccb244d87c 100644
--- a/core/fpdfdoc/doc_utils.cpp
+++ b/core/fpdfdoc/doc_utils.cpp
@@ -386,7 +386,7 @@ CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict,
if (!pFonts) {
return NULL;
}
- CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias.AsStringC());
+ CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias);
if (!pElement) {
return NULL;
}
@@ -605,8 +605,7 @@ void AddInterFormFont(CPDF_Dictionary*& pFormDict,
csNameTag.Remove(' ');
csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
csNameTag.c_str());
- pFonts->SetAtReference(csNameTag.AsStringC(), pDocument,
- pFont->GetFontDict());
+ pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict());
}
CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict,
CPDF_Document* pDocument,
@@ -650,7 +649,7 @@ void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) {
}
CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
- pFonts->RemoveAt(csTag.AsStringC());
+ pFonts->RemoveAt(csTag);
}
void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) {
if (!pFormDict || csNameTag.IsEmpty()) {
@@ -664,7 +663,7 @@ void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) {
if (!pFonts) {
return;
}
- pFonts->RemoveAt(csNameTag.AsStringC());
+ pFonts->RemoveAt(csNameTag);
}
CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict,