summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-07-18 04:52:18 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-18 04:52:18 +0000
commitbeb56d69a7a57317d521bab927a651fb260f5404 (patch)
treeb2f0ba0b35af67635ff3e72a57b802ca5b5cfa2b /core/fpdfapi/parser
parent084c31d93439d5166c60dbfb0ccee6db1406d09c (diff)
downloadpdfium-beb56d69a7a57317d521bab927a651fb260f5404.tar.xz
Avoid writing const/non-const versions of the same function.
Use const_cast for the non-const version to call the const version. Change-Id: Ibdf5fe53255ee6e983555080336f5d63e683afd1 Reviewed-on: https://pdfium-review.googlesource.com/37490 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.cpp18
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp4
2 files changed, 8 insertions, 14 deletions
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 071461b756..78227ae70a 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -87,8 +87,8 @@ const CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) const {
}
CPDF_Object* CPDF_Dictionary::GetObjectFor(const ByteString& key) {
- auto it = m_Map.find(key);
- return it != m_Map.end() ? it->second.get() : nullptr;
+ return const_cast<CPDF_Object*>(
+ static_cast<const CPDF_Dictionary*>(this)->GetObjectFor(key));
}
const CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(
@@ -98,8 +98,8 @@ const CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(
}
CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(const ByteString& key) {
- CPDF_Object* p = GetObjectFor(key);
- return p ? p->GetDirect() : nullptr;
+ return const_cast<CPDF_Object*>(
+ static_cast<const CPDF_Dictionary*>(this)->GetDirectObjectFor(key));
}
ByteString CPDF_Dictionary::GetStringFor(const ByteString& key) const {
@@ -154,14 +154,8 @@ const CPDF_Dictionary* CPDF_Dictionary::GetDictFor(
}
CPDF_Dictionary* CPDF_Dictionary::GetDictFor(const ByteString& key) {
- CPDF_Object* p = GetDirectObjectFor(key);
- if (!p)
- return nullptr;
- if (CPDF_Dictionary* pDict = p->AsDictionary())
- return pDict;
- if (CPDF_Stream* pStream = p->AsStream())
- return pStream->GetDict();
- return nullptr;
+ return const_cast<CPDF_Dictionary*>(
+ static_cast<const CPDF_Dictionary*>(this)->GetDictFor(key));
}
const CPDF_Array* CPDF_Dictionary::GetArrayFor(const ByteString& key) const {
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 2a825d7a9e..7641dbd702 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -329,8 +329,8 @@ const CPDF_Dictionary* CPDF_Document::GetPagesDict() const {
}
CPDF_Dictionary* CPDF_Document::GetPagesDict() {
- CPDF_Dictionary* pRoot = GetRoot();
- return pRoot ? pRoot->GetDictFor("Pages") : nullptr;
+ return const_cast<CPDF_Dictionary*>(
+ static_cast<const CPDF_Document*>(this)->GetPagesDict());
}
bool CPDF_Document::IsPageLoaded(int iPage) const {