summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-04-13 13:25:26 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-04-13 20:51:05 +0000
commit7062b2632ffa351903e508003788b67a8c8aba77 (patch)
tree047730e000ff7127ec834a55e7a416cb7ff4c929
parent742977f943b30638427d1ef6532acbc3d1c36bff (diff)
downloadpdfium-7062b2632ffa351903e508003788b67a8c8aba77.tar.xz
Use vector of unique ptr in cpdf_data_avail.cpp.
Remove member m_pAcroForm as it is only used in one method, and immediately set upon entry. A local will be fine here. Change-Id: I373f68252249a248061828530098ad759907259a Reviewed-on: https://pdfium-review.googlesource.com/4190 Reviewed-by: dsinclair <dsinclair@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp31
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.h3
2 files changed, 16 insertions, 18 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index aa0b4fdad6..0d6154a73b 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -71,7 +71,6 @@ CPDF_DataAvail::CPDF_DataAvail(
m_bLinearizedFormParamLoad = false;
m_pTrailer = nullptr;
m_pCurrentParser = nullptr;
- m_pAcroForm = nullptr;
m_pPageDict = nullptr;
m_pPageResource = nullptr;
m_docStatus = PDF_DATAAVAIL_HEADER;
@@ -83,8 +82,6 @@ CPDF_DataAvail::CPDF_DataAvail(
CPDF_DataAvail::~CPDF_DataAvail() {
m_pHintTables.reset();
- for (CPDF_Object* pObject : m_arrayAcroforms)
- delete pObject;
}
void CPDF_DataAvail::SetDocument(CPDF_Document* pDoc) {
@@ -206,8 +203,12 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail(
bool CPDF_DataAvail::CheckAcroFormSubObject(DownloadHints* pHints) {
if (m_objs_array.empty()) {
+ std::vector<CPDF_Object*> obj_array(m_Acroforms.size());
+ std::transform(
+ m_Acroforms.begin(), m_Acroforms.end(), obj_array.begin(),
+ [](const std::unique_ptr<CPDF_Object>& pObj) { return pObj.get(); });
+
m_ObjectSet.clear();
- std::vector<CPDF_Object*> obj_array = m_arrayAcroforms;
if (!AreObjectsAvailable(obj_array, false, pHints, m_objs_array))
return false;
@@ -221,30 +222,28 @@ bool CPDF_DataAvail::CheckAcroFormSubObject(DownloadHints* pHints) {
return false;
}
- for (CPDF_Object* pObject : m_arrayAcroforms)
- delete pObject;
-
- m_arrayAcroforms.clear();
+ m_Acroforms.clear();
return true;
}
bool CPDF_DataAvail::CheckAcroForm(DownloadHints* pHints) {
bool bExist = false;
- m_pAcroForm = GetObject(m_dwAcroFormObjNum, pHints, &bExist).release();
+ std::unique_ptr<CPDF_Object> pAcroForm =
+ GetObject(m_dwAcroFormObjNum, pHints, &bExist);
if (!bExist) {
m_docStatus = PDF_DATAAVAIL_PAGETREE;
return true;
}
- if (!m_pAcroForm) {
- if (m_docStatus == PDF_DATAAVAIL_ERROR) {
- m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
- return true;
- }
- return false;
+ if (!pAcroForm) {
+ if (m_docStatus != PDF_DATAAVAIL_ERROR)
+ return false;
+
+ m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
+ return true;
}
- m_arrayAcroforms.push_back(m_pAcroForm);
+ m_Acroforms.push_back(std::move(pAcroForm));
m_docStatus = PDF_DATAAVAIL_PAGETREE;
return true;
}
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h
index 62c5d49c9d..8edf062590 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.h
+++ b/core/fpdfapi/parser/cpdf_data_avail.h
@@ -235,8 +235,7 @@ class CPDF_DataAvail final {
bool m_bHaveAcroForm;
uint32_t m_dwAcroFormObjNum;
bool m_bAcroFormLoad;
- CPDF_Object* m_pAcroForm;
- std::vector<CPDF_Object*> m_arrayAcroforms;
+ std::vector<std::unique_ptr<CPDF_Object>> m_Acroforms;
CPDF_Dictionary* m_pPageDict;
CPDF_Object* m_pPageResource;
bool m_bNeedDownLoadResource;