summaryrefslogtreecommitdiff
path: root/core/src/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-12-09 16:26:21 -0800
committerTom Sepez <tsepez@chromium.org>2015-12-09 16:26:21 -0800
commit035359cd8ddb555fa33b6133db4fd405e4660712 (patch)
tree89accecac7da250468166168cd502ed7b92c7ce7 /core/src/fpdfapi/fpdf_parser
parent0c92bed7ade20fe193dce0a481dad48e1be41622 (diff)
downloadpdfium-035359cd8ddb555fa33b6133db4fd405e4660712.tar.xz
Get rid of most uses of CFX_PtrArray.
I didn't go whole hog and replace these with std::vector, but in the mean time, it is silly to cast a typedef for a template instantiated against void* when we can just instantiate the template against the actual type. The ones that remain are actual heterogeneous arrays with wacky casting. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1518593002 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp5
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp36
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp59
3 files changed, 48 insertions, 52 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 57d1971889..dbd5f311a6 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -335,7 +335,7 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
CPDF_Object* pParams =
pDict ? pDict->GetElementValue(FX_BSTRC("DecodeParms")) : nullptr;
CFX_ByteStringArray DecoderList;
- CFX_PtrArray ParamList;
+ CFX_ArrayTemplate<CPDF_Object*> ParamList;
if (CPDF_Array* pDecoders = pDecoder->AsArray()) {
CPDF_Array* pParamsArray = ToArray(pParams);
if (!pParamsArray)
@@ -357,8 +357,7 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
i == DecoderList.GetSize() - 1 ? last_estimated_size : 0;
CFX_ByteString decoder = DecoderList[i];
// Use ToDictionary here because we can push NULL into the ParamList.
- CPDF_Dictionary* pParam =
- ToDictionary(static_cast<CPDF_Object*>(ParamList[i]));
+ CPDF_Dictionary* pParam = ToDictionary(ParamList[i]);
uint8_t* new_buf = nullptr;
FX_DWORD new_size = (FX_DWORD)-1;
int offset = -1;
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
index edf80d0618..752a09d83d 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp
@@ -251,8 +251,7 @@ CPDF_Object* CPDF_Object::CloneInternal(FX_BOOL bDirect,
const CPDF_Array* pThis = AsArray();
int n = pThis->GetCount();
for (int i = 0; i < n; i++) {
- CPDF_Object* value =
- static_cast<CPDF_Object*>(pThis->m_Objects.GetAt(i));
+ CPDF_Object* value = pThis->m_Objects.GetAt(i);
pCopy->m_Objects.Add(value->CloneInternal(bDirect, visited));
}
return pCopy;
@@ -424,7 +423,7 @@ CPDF_String::CPDF_String(const CFX_WideString& str)
}
CPDF_Array::~CPDF_Array() {
int size = m_Objects.GetSize();
- CPDF_Object** pList = (CPDF_Object**)m_Objects.GetData();
+ CPDF_Object** pList = m_Objects.GetData();
for (int i = 0; i < size; i++) {
if (pList[i])
pList[i]->Release();
@@ -453,32 +452,32 @@ CFX_AffineMatrix CPDF_Array::GetMatrix() {
CPDF_Object* CPDF_Array::GetElement(FX_DWORD i) const {
if (i >= (FX_DWORD)m_Objects.GetSize())
return nullptr;
- return static_cast<CPDF_Object*>(m_Objects.GetAt(i));
+ return m_Objects.GetAt(i);
}
CPDF_Object* CPDF_Array::GetElementValue(FX_DWORD i) const {
if (i >= (FX_DWORD)m_Objects.GetSize())
return nullptr;
- return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetDirect();
+ return m_Objects.GetAt(i)->GetDirect();
}
CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const {
- if (i < (FX_DWORD)m_Objects.GetSize())
- return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetString();
- return CFX_ByteString();
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return CFX_ByteString();
+ return m_Objects.GetAt(i)->GetString();
}
CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const {
- if (i < (FX_DWORD)m_Objects.GetSize())
- return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetConstString();
- return CFX_ByteStringC();
+ if (i >= (FX_DWORD)m_Objects.GetSize())
+ return CFX_ByteStringC();
+ return m_Objects.GetAt(i)->GetConstString();
}
int CPDF_Array::GetInteger(FX_DWORD i) const {
if (i >= (FX_DWORD)m_Objects.GetSize())
return 0;
- return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetInteger();
+ return m_Objects.GetAt(i)->GetInteger();
}
FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const {
if (i >= (FX_DWORD)m_Objects.GetSize())
return 0;
- return static_cast<CPDF_Object*>(m_Objects.GetAt(i))->GetNumber();
+ return m_Objects.GetAt(i)->GetNumber();
}
CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const {
CPDF_Object* p = GetElementValue(i);
@@ -504,7 +503,7 @@ void CPDF_Array::RemoveAt(FX_DWORD i, int nCount) {
return;
for (int j = 0; j < nCount; ++j) {
- if (CPDF_Object* p = static_cast<CPDF_Object*>(m_Objects.GetAt(i + j)))
+ if (CPDF_Object* p = m_Objects.GetAt(i + j))
p->Release();
}
m_Objects.RemoveAt(i, nCount);
@@ -516,7 +515,7 @@ void CPDF_Array::SetAt(FX_DWORD i,
ASSERT(i < (FX_DWORD)m_Objects.GetSize());
if (i >= (FX_DWORD)m_Objects.GetSize())
return;
- if (CPDF_Object* pOld = static_cast<CPDF_Object*>(m_Objects.GetAt(i)))
+ if (CPDF_Object* pOld = m_Objects.GetAt(i))
pOld->Release();
if (pObj->GetObjNum()) {
ASSERT(pObjs);
@@ -568,11 +567,10 @@ FX_BOOL CPDF_Array::Identical(CPDF_Array* pOther) const {
if (m_Objects.GetSize() != pOther->m_Objects.GetSize()) {
return FALSE;
}
- for (int i = 0; i < m_Objects.GetSize(); i++)
- if (!static_cast<CPDF_Object*>(m_Objects[i])
- ->IsIdentical(static_cast<CPDF_Object*>(pOther->m_Objects[i]))) {
+ for (int i = 0; i < m_Objects.GetSize(); i++) {
+ if (!m_Objects[i]->IsIdentical(pOther->m_Objects[i]))
return FALSE;
- }
+ }
return TRUE;
}
CPDF_Dictionary::~CPDF_Dictionary() {
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 04aca91082..f64ba0deb0 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2693,10 +2693,10 @@ class CPDF_DataAvail final : public IPDF_DataAvail {
static const int kMaxPageRecursionDepth = 1024;
FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset);
- FX_BOOL IsObjectsAvail(CFX_PtrArray& obj_array,
+ FX_BOOL IsObjectsAvail(CFX_ArrayTemplate<CPDF_Object*>& obj_array,
FX_BOOL bParsePage,
IFX_DownloadHints* pHints,
- CFX_PtrArray& ret_array);
+ CFX_ArrayTemplate<CPDF_Object*>& ret_array);
FX_BOOL CheckDocStatus(IFX_DownloadHints* pHints);
FX_BOOL CheckHeader(IFX_DownloadHints* pHints);
FX_BOOL CheckFirstPage(IFX_DownloadHints* pHints);
@@ -2795,7 +2795,7 @@ class CPDF_DataAvail final : public IPDF_DataAvail {
CPDF_SortObjNumArray m_objnum_array;
- CFX_PtrArray m_objs_array;
+ CFX_ArrayTemplate<CPDF_Object*> m_objs_array;
FX_FILESIZE m_Pos;
@@ -2847,7 +2847,7 @@ class CPDF_DataAvail final : public IPDF_DataAvail {
CPDF_Object* m_pAcroForm;
- CFX_PtrArray m_arrayAcroforms;
+ CFX_ArrayTemplate<CPDF_Object*> m_arrayAcroforms;
CPDF_Dictionary* m_pPageDict;
@@ -2859,7 +2859,7 @@ class CPDF_DataAvail final : public IPDF_DataAvail {
FX_BOOL m_bLinearizedFormParamLoad;
- CFX_PtrArray m_PagesArray;
+ CFX_ArrayTemplate<CPDF_Object*> m_PagesArray;
FX_DWORD m_dwEncryptObjNum;
@@ -2954,7 +2954,7 @@ CPDF_DataAvail::~CPDF_DataAvail() {
int iSize = m_arrayAcroforms.GetSize();
for (int i = 0; i < iSize; ++i) {
- static_cast<CPDF_Object*>(m_arrayAcroforms.GetAt(i))->Release();
+ m_arrayAcroforms.GetAt(i)->Release();
}
}
void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) {
@@ -2991,18 +2991,19 @@ FX_DWORD CPDF_DataAvail::GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset) {
}
return 0;
}
-FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array,
- FX_BOOL bParsePage,
- IFX_DownloadHints* pHints,
- CFX_PtrArray& ret_array) {
+FX_BOOL CPDF_DataAvail::IsObjectsAvail(
+ CFX_ArrayTemplate<CPDF_Object*>& obj_array,
+ FX_BOOL bParsePage,
+ IFX_DownloadHints* pHints,
+ CFX_ArrayTemplate<CPDF_Object*>& ret_array) {
if (!obj_array.GetSize()) {
return TRUE;
}
FX_DWORD count = 0;
- CFX_PtrArray new_obj_array;
+ CFX_ArrayTemplate<CPDF_Object*> new_obj_array;
int32_t i = 0;
for (i = 0; i < obj_array.GetSize(); i++) {
- CPDF_Object* pObj = static_cast<CPDF_Object*>(obj_array[i]);
+ CPDF_Object* pObj = obj_array[i];
if (!pObj)
continue;
@@ -3056,7 +3057,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(CFX_PtrArray& obj_array,
if (count > 0) {
int32_t iSize = new_obj_array.GetSize();
for (i = 0; i < iSize; ++i) {
- CPDF_Object* pObj = static_cast<CPDF_Object*>(new_obj_array[i]);
+ CPDF_Object* pObj = new_obj_array[i];
if (CPDF_Reference* pRef = pObj->AsReference()) {
FX_DWORD dwNum = pRef->GetRefObjNum();
if (!m_objnum_array.Find(dwNum))
@@ -3092,7 +3093,7 @@ FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) {
if (!m_objs_array.GetSize()) {
m_objs_array.RemoveAll();
m_objnum_array.RemoveAll();
- CFX_PtrArray obj_array;
+ CFX_ArrayTemplate<CPDF_Object*> obj_array;
obj_array.Append(m_arrayAcroforms);
FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array);
if (bRet) {
@@ -3100,12 +3101,12 @@ FX_BOOL CPDF_DataAvail::CheckAcroFormSubObject(IFX_DownloadHints* pHints) {
}
return bRet;
}
- CFX_PtrArray new_objs_array;
+ CFX_ArrayTemplate<CPDF_Object*> new_objs_array;
FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
if (bRet) {
int32_t iSize = m_arrayAcroforms.GetSize();
for (int32_t i = 0; i < iSize; ++i) {
- static_cast<CPDF_Object*>(m_arrayAcroforms.GetAt(i))->Release();
+ m_arrayAcroforms.GetAt(i)->Release();
}
m_arrayAcroforms.RemoveAll();
} else {
@@ -3391,14 +3392,14 @@ FX_BOOL CPDF_DataAvail::CheckPage(IFX_DownloadHints* pHints) {
}
FX_DWORD iPages = m_PagesArray.GetSize();
for (FX_DWORD i = 0; i < iPages; i++) {
- CPDF_Object* pPages = static_cast<CPDF_Object*>(m_PagesArray.GetAt(i));
+ CPDF_Object* pPages = m_PagesArray.GetAt(i);
if (!pPages)
continue;
if (!GetPageKids(m_pCurrentParser, pPages)) {
pPages->Release();
while (++i < iPages) {
- pPages = static_cast<CPDF_Object*>(m_PagesArray.GetAt(i));
+ pPages = m_PagesArray.GetAt(i);
pPages->Release();
}
m_PagesArray.RemoveAll();
@@ -4163,7 +4164,7 @@ FX_BOOL CPDF_DataAvail::CheckPageNode(CPDF_PageNode& pageNodes,
return FALSE;
}
for (int32_t i = 0; i < iSize; ++i) {
- CPDF_PageNode* pNode = (CPDF_PageNode*)pageNodes.m_childNode.GetAt(i);
+ CPDF_PageNode* pNode = pageNodes.m_childNode.GetAt(i);
if (!pNode) {
continue;
}
@@ -4310,7 +4311,7 @@ FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage,
if (!pAnnots) {
return TRUE;
}
- CFX_PtrArray obj_array;
+ CFX_ArrayTemplate<CPDF_Object*> obj_array;
obj_array.Add(pAnnots);
FX_BOOL bRet = IsObjectsAvail(obj_array, FALSE, pHints, m_objs_array);
if (bRet) {
@@ -4318,7 +4319,7 @@ FX_BOOL CPDF_DataAvail::CheckPageAnnots(int32_t iPage,
}
return bRet;
}
- CFX_PtrArray new_objs_array;
+ CFX_ArrayTemplate<CPDF_Object*> new_objs_array;
FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
m_objs_array.RemoveAll();
if (!bRet) {
@@ -4432,7 +4433,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
ResetFirstCheck(iPage);
return DataAvailable;
}
- CFX_PtrArray obj_array;
+ CFX_ArrayTemplate<CPDF_Object*> obj_array;
obj_array.Add(m_pPageDict);
FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array);
if (bRet) {
@@ -4442,7 +4443,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
return bRet;
}
} else {
- CFX_PtrArray new_objs_array;
+ CFX_ArrayTemplate<CPDF_Object*> new_objs_array;
FX_BOOL bRet =
IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
m_objs_array.RemoveAll();
@@ -4487,7 +4488,7 @@ int CPDF_DataAvail::IsPageAvail(int32_t iPage, IFX_DownloadHints* pHints) {
FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) {
if (!m_objs_array.GetSize()) {
m_objs_array.RemoveAll();
- CFX_PtrArray obj_array;
+ CFX_ArrayTemplate<CPDF_Object*> obj_array;
obj_array.Add(m_pPageResource);
FX_BOOL bRet = IsObjectsAvail(obj_array, TRUE, pHints, m_objs_array);
if (bRet) {
@@ -4495,7 +4496,7 @@ FX_BOOL CPDF_DataAvail::CheckResources(IFX_DownloadHints* pHints) {
}
return bRet;
}
- CFX_PtrArray new_objs_array;
+ CFX_ArrayTemplate<CPDF_Object*> new_objs_array;
FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
m_objs_array.RemoveAll();
if (!bRet) {
@@ -4570,7 +4571,7 @@ IPDF_DataAvail::DocFormStatus CPDF_DataAvail::IsFormAvail(
}
m_bLinearizedFormParamLoad = TRUE;
}
- CFX_PtrArray new_objs_array;
+ CFX_ArrayTemplate<CPDF_Object*> new_objs_array;
FX_BOOL bRet = IsObjectsAvail(m_objs_array, FALSE, pHints, new_objs_array);
m_objs_array.RemoveAll();
if (!bRet) {
@@ -4609,10 +4610,8 @@ FX_BOOL CPDF_SortObjNumArray::BinarySearch(FX_DWORD value, int32_t& iNext) {
return FALSE;
}
CPDF_PageNode::~CPDF_PageNode() {
- int32_t iSize = m_childNode.GetSize();
- for (int32_t i = 0; i < iSize; ++i) {
- CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i];
- delete pNode;
+ for (int32_t i = 0; i < m_childNode.GetSize(); ++i) {
+ delete m_childNode[i];
}
m_childNode.RemoveAll();
}