summaryrefslogtreecommitdiff
path: root/core/fpdfapi/fpdf_parser
diff options
context:
space:
mode:
authorWei Li <weili@chromium.org>2016-04-11 10:02:09 -0700
committerWei Li <weili@chromium.org>2016-04-11 10:02:09 -0700
commite1aebd43b0c75133f94f8b141b33d12e2e715524 (patch)
tree863aded8c706db162eb3f69d6482100f9d61b842 /core/fpdfapi/fpdf_parser
parent2d4a4fc372159ac7562abea48498b6ab72c2f321 (diff)
downloadpdfium-e1aebd43b0c75133f94f8b141b33d12e2e715524.tar.xz
Use std::vector as internal storage for CPDF_Array
Replace the usage of CFX_ArrayTemplate inside CPDF_Array, which has non-standard APIs such as GetSize() returns int. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1867183002 .
Diffstat (limited to 'core/fpdfapi/fpdf_parser')
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_array.cpp93
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp17
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_document.cpp13
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_parser.cpp5
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp2
-rw-r--r--core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp2
-rw-r--r--core/fpdfapi/fpdf_parser/include/cpdf_array.h32
7 files changed, 83 insertions, 81 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_array.cpp b/core/fpdfapi/fpdf_parser/cpdf_array.cpp
index 964ba64236..e2279c8e1d 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_array.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_array.cpp
@@ -15,11 +15,9 @@
CPDF_Array::CPDF_Array() {}
CPDF_Array::~CPDF_Array() {
- int size = m_Objects.GetSize();
- CPDF_Object** pList = m_Objects.GetData();
- for (int i = 0; i < size; i++) {
- if (pList[i])
- pList[i]->Release();
+ for (auto& it : m_Objects) {
+ if (it)
+ it->Release();
}
}
@@ -48,15 +46,15 @@ const CPDF_Array* CPDF_Array::AsArray() const {
CPDF_Object* CPDF_Array::Clone(FX_BOOL bDirect) const {
CPDF_Array* pCopy = new CPDF_Array();
for (size_t i = 0; i < GetCount(); i++) {
- CPDF_Object* value = m_Objects.GetAt(i);
- pCopy->m_Objects.Add(value->Clone(bDirect));
+ CPDF_Object* value = m_Objects.at(i);
+ pCopy->m_Objects.push_back(value->Clone(bDirect));
}
return pCopy;
}
CFX_FloatRect CPDF_Array::GetRect() {
CFX_FloatRect rect;
- if (!IsArray() || m_Objects.GetSize() != 4)
+ if (!IsArray() || m_Objects.size() != 4)
return rect;
rect.left = GetNumberAt(0);
@@ -68,7 +66,7 @@ CFX_FloatRect CPDF_Array::GetRect() {
CFX_Matrix CPDF_Array::GetMatrix() {
CFX_Matrix matrix;
- if (!IsArray() || m_Objects.GetSize() != 6)
+ if (!IsArray() || m_Objects.size() != 6)
return matrix;
matrix.Set(GetNumberAt(0), GetNumberAt(1), GetNumberAt(2), GetNumberAt(3),
@@ -76,43 +74,43 @@ CFX_Matrix CPDF_Array::GetMatrix() {
return matrix;
}
-CPDF_Object* CPDF_Array::GetObjectAt(uint32_t i) const {
- if (i >= (uint32_t)m_Objects.GetSize())
+CPDF_Object* CPDF_Array::GetObjectAt(size_t i) const {
+ if (i >= m_Objects.size())
return nullptr;
- return m_Objects.GetAt(i);
+ return m_Objects.at(i);
}
-CPDF_Object* CPDF_Array::GetDirectObjectAt(uint32_t i) const {
- if (i >= (uint32_t)m_Objects.GetSize())
+CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) const {
+ if (i >= m_Objects.size())
return nullptr;
- return m_Objects.GetAt(i)->GetDirect();
+ return m_Objects.at(i)->GetDirect();
}
-CFX_ByteString CPDF_Array::GetStringAt(uint32_t i) const {
- if (i >= (uint32_t)m_Objects.GetSize())
+CFX_ByteString CPDF_Array::GetStringAt(size_t i) const {
+ if (i >= m_Objects.size())
return CFX_ByteString();
- return m_Objects.GetAt(i)->GetString();
+ return m_Objects.at(i)->GetString();
}
-CFX_ByteStringC CPDF_Array::GetConstStringAt(uint32_t i) const {
- if (i >= (uint32_t)m_Objects.GetSize())
+CFX_ByteStringC CPDF_Array::GetConstStringAt(size_t i) const {
+ if (i >= m_Objects.size())
return CFX_ByteStringC();
- return m_Objects.GetAt(i)->GetConstString();
+ return m_Objects.at(i)->GetConstString();
}
-int CPDF_Array::GetIntegerAt(uint32_t i) const {
- if (i >= (uint32_t)m_Objects.GetSize())
+int CPDF_Array::GetIntegerAt(size_t i) const {
+ if (i >= m_Objects.size())
return 0;
- return m_Objects.GetAt(i)->GetInteger();
+ return m_Objects.at(i)->GetInteger();
}
-FX_FLOAT CPDF_Array::GetNumberAt(uint32_t i) const {
- if (i >= (uint32_t)m_Objects.GetSize())
+FX_FLOAT CPDF_Array::GetNumberAt(size_t i) const {
+ if (i >= m_Objects.size())
return 0;
- return m_Objects.GetAt(i)->GetNumber();
+ return m_Objects.at(i)->GetNumber();
}
-CPDF_Dictionary* CPDF_Array::GetDictAt(uint32_t i) const {
+CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const {
CPDF_Object* p = GetDirectObjectAt(i);
if (!p)
return NULL;
@@ -123,52 +121,59 @@ CPDF_Dictionary* CPDF_Array::GetDictAt(uint32_t i) const {
return NULL;
}
-CPDF_Stream* CPDF_Array::GetStreamAt(uint32_t i) const {
+CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) const {
return ToStream(GetDirectObjectAt(i));
}
-CPDF_Array* CPDF_Array::GetArrayAt(uint32_t i) const {
+CPDF_Array* CPDF_Array::GetArrayAt(size_t i) const {
return ToArray(GetDirectObjectAt(i));
}
-void CPDF_Array::RemoveAt(uint32_t i, uint32_t nCount) {
- if (i >= (uint32_t)m_Objects.GetSize())
+void CPDF_Array::RemoveAt(size_t i, size_t nCount) {
+ if (i >= m_Objects.size())
return;
- if (nCount <= 0 || nCount > m_Objects.GetSize() - i)
+ if (nCount <= 0 || nCount > m_Objects.size() - i)
return;
- for (uint32_t j = 0; j < nCount; ++j) {
- if (CPDF_Object* p = m_Objects.GetAt(i + j))
+ for (size_t j = 0; j < nCount; ++j) {
+ if (CPDF_Object* p = m_Objects.at(i + j))
p->Release();
}
- m_Objects.RemoveAt(i, nCount);
+ m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount);
}
-void CPDF_Array::SetAt(uint32_t i,
+void CPDF_Array::SetAt(size_t i,
CPDF_Object* pObj,
CPDF_IndirectObjectHolder* pObjs) {
ASSERT(IsArray());
- ASSERT(i < (uint32_t)m_Objects.GetSize());
- if (i >= (uint32_t)m_Objects.GetSize())
+ ASSERT(i < m_Objects.size());
+ if (i >= m_Objects.size())
return;
- if (CPDF_Object* pOld = m_Objects.GetAt(i))
+ if (CPDF_Object* pOld = m_Objects.at(i))
pOld->Release();
if (pObj->GetObjNum()) {
ASSERT(pObjs);
pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
}
- m_Objects.SetAt(i, pObj);
+ m_Objects[i] = pObj;
}
-void CPDF_Array::InsertAt(uint32_t index,
+void CPDF_Array::InsertAt(size_t index,
CPDF_Object* pObj,
CPDF_IndirectObjectHolder* pObjs) {
if (pObj->GetObjNum()) {
ASSERT(pObjs);
pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
}
- m_Objects.InsertAt(index, pObj);
+ if (index >= m_Objects.size()) {
+ // Allocate space first.
+ m_Objects.resize(index + 1, nullptr);
+ m_Objects[index] = pObj;
+ } else {
+ // Directly insert.
+ m_Objects.insert(m_Objects.begin() + index, pObj);
+ }
}
void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) {
@@ -176,7 +181,7 @@ void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) {
ASSERT(pObjs);
pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
}
- m_Objects.Add(pObj);
+ m_Objects.push_back(pObj);
}
void CPDF_Array::AddName(const CFX_ByteString& str) {
diff --git a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp
index 68f8b88557..e08e913f74 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_data_avail.cpp
@@ -142,8 +142,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(
uint32_t count = 0;
CFX_ArrayTemplate<CPDF_Object*> new_obj_array;
- int32_t i = 0;
- for (i = 0; i < obj_array.GetSize(); i++) {
+ for (int i = 0; i < obj_array.GetSize(); i++) {
CPDF_Object* pObj = obj_array[i];
if (!pObj)
continue;
@@ -152,7 +151,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(
switch (type) {
case CPDF_Object::ARRAY: {
CPDF_Array* pArray = pObj->GetArray();
- for (uint32_t k = 0; k < pArray->GetCount(); ++k)
+ for (size_t k = 0; k < pArray->GetCount(); ++k)
new_obj_array.Add(pArray->GetObjectAt(k));
} break;
case CPDF_Object::STREAM:
@@ -193,8 +192,7 @@ FX_BOOL CPDF_DataAvail::IsObjectsAvail(
}
if (count > 0) {
- int32_t iSize = new_obj_array.GetSize();
- for (i = 0; i < iSize; ++i) {
+ for (int i = 0; i < new_obj_array.GetSize(); ++i) {
CPDF_Object* pObj = new_obj_array[i];
if (CPDF_Reference* pRef = pObj->AsReference()) {
uint32_t dwNum = pRef->GetRefObjNum();
@@ -513,8 +511,7 @@ FX_BOOL CPDF_DataAvail::CheckPage(IPDF_DataAvail::DownloadHints* pHints) {
if (pObj->IsArray()) {
CPDF_Array* pArray = pObj->GetArray();
if (pArray) {
- int32_t iSize = pArray->GetCount();
- for (int32_t j = 0; j < iSize; ++j) {
+ for (size_t j = 0; j < pArray->GetCount(); ++j) {
if (CPDF_Reference* pRef = ToReference(pArray->GetObjectAt(j)))
UnavailObjList.Add(pRef->GetRefObjNum());
}
@@ -583,7 +580,7 @@ FX_BOOL CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) {
break;
case CPDF_Object::ARRAY: {
CPDF_Array* pKidsArray = pKids->AsArray();
- for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) {
+ for (size_t i = 0; i < pKidsArray->GetCount(); ++i) {
if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i)))
m_PageObjList.Add(pRef->GetRefObjNum());
}
@@ -1285,7 +1282,7 @@ FX_BOOL CPDF_DataAvail::CheckArrayPageNode(
}
pPageNode->m_type = PDF_PAGENODE_PAGES;
- for (uint32_t i = 0; i < pArray->GetCount(); ++i) {
+ for (size_t i = 0; i < pArray->GetCount(); ++i) {
CPDF_Reference* pKid = ToReference(pArray->GetObjectAt(i));
if (!pKid)
continue;
@@ -1348,7 +1345,7 @@ FX_BOOL CPDF_DataAvail::CheckUnkownPageNode(
} break;
case CPDF_Object::ARRAY: {
CPDF_Array* pKidsArray = pKids->AsArray();
- for (uint32_t i = 0; i < pKidsArray->GetCount(); ++i) {
+ for (size_t i = 0; i < pKidsArray->GetCount(); ++i) {
CPDF_Reference* pKid = ToReference(pKidsArray->GetObjectAt(i));
if (!pKid)
continue;
diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp
index d48edd056b..808a468016 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp
@@ -32,7 +32,7 @@ int CountPages(CPDF_Dictionary* pPages,
return 0;
}
count = 0;
- for (uint32_t i = 0; i < pKidList->GetCount(); i++) {
+ for (size_t i = 0; i < pKidList->GetCount(); i++) {
CPDF_Dictionary* pKid = pKidList->GetDictAt(i);
if (!pKid || pdfium::ContainsKey(*visited_pages, pKid)) {
continue;
@@ -155,8 +155,7 @@ CPDF_Dictionary* CPDF_Document::_FindPDFPage(CPDF_Dictionary* pPages,
if (level >= FX_MAX_PAGE_LEVEL) {
return NULL;
}
- int nKids = pKidList->GetCount();
- for (int i = 0; i < nKids; i++) {
+ for (size_t i = 0; i < pKidList->GetCount(); i++) {
CPDF_Dictionary* pKid = pKidList->GetDictAt(i);
if (!pKid) {
nPagesToGo--;
@@ -228,23 +227,23 @@ int CPDF_Document::_FindPageIndex(CPDF_Dictionary* pNode,
if (level >= FX_MAX_PAGE_LEVEL) {
return -1;
}
- uint32_t count = pNode->GetIntegerBy("Count");
+ size_t count = pNode->GetIntegerBy("Count");
if (count <= skip_count) {
skip_count -= count;
index += count;
return -1;
}
if (count && count == pKidList->GetCount()) {
- for (uint32_t i = 0; i < count; i++) {
+ for (size_t i = 0; i < count; i++) {
if (CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i))) {
if (pKid->GetRefObjNum() == objnum) {
m_PageList.SetAt(index + i, objnum);
- return index + i;
+ return static_cast<int>(index + i);
}
}
}
}
- for (uint32_t i = 0; i < pKidList->GetCount(); i++) {
+ for (size_t i = 0; i < pKidList->GetCount(); i++) {
CPDF_Dictionary* pKid = pKidList->GetDictAt(i);
if (!pKid) {
continue;
diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp
index 4ba43678b8..97b03f046c 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp
@@ -988,8 +988,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) {
std::vector<std::pair<int32_t, int32_t>> arrIndex;
CPDF_Array* pArray = pStream->GetDict()->GetArrayBy("Index");
if (pArray) {
- uint32_t nPairSize = pArray->GetCount() / 2;
- for (uint32_t i = 0; i < nPairSize; i++) {
+ for (size_t i = 0; i < pArray->GetCount() / 2; i++) {
CPDF_Object* pStartNumObj = pArray->GetObjectAt(i * 2);
CPDF_Object* pCountObj = pArray->GetObjectAt(i * 2 + 1);
@@ -1013,7 +1012,7 @@ FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) {
CFX_ArrayTemplate<uint32_t> WidthArray;
FX_SAFE_UINT32 dwAccWidth = 0;
- for (uint32_t i = 0; i < pArray->GetCount(); i++) {
+ for (size_t i = 0; i < pArray->GetCount(); i++) {
WidthArray.Add(pArray->GetIntegerAt(i));
dwAccWidth += WidthArray[i];
}
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
index 0a7729fe4b..11d9e524ee 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp
@@ -349,7 +349,7 @@ FX_BOOL PDF_DataDecode(const uint8_t* src_buf,
if (!pParamsArray)
pParams = nullptr;
- for (uint32_t i = 0; i < pDecoders->GetCount(); i++) {
+ for (size_t i = 0; i < pDecoders->GetCount(); i++) {
DecoderList.push_back(pDecoders->GetConstStringAt(i));
ParamList.Add(pParams ? pParamsArray->GetDictAt(i) : nullptr);
}
diff --git a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
index 31e7388bd7..bfd0de44b6 100644
--- a/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp
@@ -179,7 +179,7 @@ CFX_ByteTextBuf& operator<<(CFX_ByteTextBuf& buf, const CPDF_Object* pObj) {
case CPDF_Object::ARRAY: {
const CPDF_Array* p = pObj->AsArray();
buf << "[";
- for (uint32_t i = 0; i < p->GetCount(); i++) {
+ for (size_t i = 0; i < p->GetCount(); i++) {
CPDF_Object* pElement = p->GetObjectAt(i);
if (pElement->GetObjNum()) {
buf << " " << pElement->GetObjNum() << " 0 R";
diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_array.h b/core/fpdfapi/fpdf_parser/include/cpdf_array.h
index b964f4955b..506a6bc338 100644
--- a/core/fpdfapi/fpdf_parser/include/cpdf_array.h
+++ b/core/fpdfapi/fpdf_parser/include/cpdf_array.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_
#define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_
+#include <vector>
+
#include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
#include "core/fxcrt/include/fx_basic.h"
@@ -24,27 +26,27 @@ class CPDF_Array : public CPDF_Object {
CPDF_Array* AsArray() override;
const CPDF_Array* AsArray() const override;
- uint32_t GetCount() const { return m_Objects.GetSize(); }
- CPDF_Object* GetObjectAt(uint32_t index) const;
- CPDF_Object* GetDirectObjectAt(uint32_t index) const;
- CFX_ByteString GetStringAt(uint32_t index) const;
- CFX_ByteStringC GetConstStringAt(uint32_t index) const;
- int GetIntegerAt(uint32_t index) const;
- FX_FLOAT GetNumberAt(uint32_t index) const;
- CPDF_Dictionary* GetDictAt(uint32_t index) const;
- CPDF_Stream* GetStreamAt(uint32_t index) const;
- CPDF_Array* GetArrayAt(uint32_t index) const;
- FX_FLOAT GetFloatAt(uint32_t index) const { return GetNumberAt(index); }
+ size_t GetCount() const { return m_Objects.size(); }
+ CPDF_Object* GetObjectAt(size_t index) const;
+ CPDF_Object* GetDirectObjectAt(size_t index) const;
+ CFX_ByteString GetStringAt(size_t index) const;
+ CFX_ByteStringC GetConstStringAt(size_t index) const;
+ int GetIntegerAt(size_t index) const;
+ FX_FLOAT GetNumberAt(size_t index) const;
+ CPDF_Dictionary* GetDictAt(size_t index) const;
+ CPDF_Stream* GetStreamAt(size_t index) const;
+ CPDF_Array* GetArrayAt(size_t index) const;
+ FX_FLOAT GetFloatAt(size_t index) const { return GetNumberAt(index); }
CFX_Matrix GetMatrix();
CFX_FloatRect GetRect();
- void SetAt(uint32_t index,
+ void SetAt(size_t index,
CPDF_Object* pObj,
CPDF_IndirectObjectHolder* pObjs = nullptr);
- void InsertAt(uint32_t index,
+ void InsertAt(size_t index,
CPDF_Object* pObj,
CPDF_IndirectObjectHolder* pObjs = nullptr);
- void RemoveAt(uint32_t index, uint32_t nCount = 1);
+ void RemoveAt(size_t index, size_t nCount = 1);
void Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs = nullptr);
void AddNumber(FX_FLOAT f);
@@ -59,7 +61,7 @@ class CPDF_Array : public CPDF_Object {
protected:
~CPDF_Array() override;
- CFX_ArrayTemplate<CPDF_Object*> m_Objects;
+ std::vector<CPDF_Object*> m_Objects;
};
#endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_ARRAY_H_