Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Unified Diff: core/fpdfapi/parser/cpdf_array.cpp

Issue 2484033002: Return unique_ptr from CPDF_Object::Clone(). (Closed)
Patch Set: Be painfully obvious about hidden expression Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfapi/parser/cpdf_array.cpp
diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp
index 4000bbc98088e3fecf7531f020a7093fd9fc54c9..502424ba07967d99a137031621a3f4d9be4c675b 100644
--- a/core/fpdfapi/parser/cpdf_array.cpp
+++ b/core/fpdfapi/parser/cpdf_array.cpp
@@ -44,21 +44,22 @@ const CPDF_Array* CPDF_Array::AsArray() const {
return this;
}
-CPDF_Object* CPDF_Array::Clone() const {
+std::unique_ptr<CPDF_Object> CPDF_Array::Clone() const {
return CloneObjectNonCyclic(false);
}
-CPDF_Object* CPDF_Array::CloneNonCyclic(
+std::unique_ptr<CPDF_Object> CPDF_Array::CloneNonCyclic(
bool bDirect,
std::set<const CPDF_Object*>* pVisited) const {
pVisited->insert(this);
- CPDF_Array* pCopy = new CPDF_Array();
- for (size_t i = 0; i < GetCount(); i++) {
- CPDF_Object* value = m_Objects[i];
- if (!pdfium::ContainsKey(*pVisited, value))
- pCopy->m_Objects.push_back(value->CloneNonCyclic(bDirect, pVisited));
+ auto pCopy = pdfium::MakeUnique<CPDF_Array>();
+ for (CPDF_Object* value : m_Objects) {
+ if (!pdfium::ContainsKey(*pVisited, value)) {
+ pCopy->m_Objects.push_back(
+ value->CloneNonCyclic(bDirect, pVisited).release());
+ }
}
- return pCopy;
+ return std::unique_ptr<CPDF_Object>(std::move(pCopy));
}
CFX_FloatRect CPDF_Array::GetRect() {

Powered by Google App Engine
This is Rietveld 408576698