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

Side by Side Diff: core/fpdfapi/parser/cpdf_dictionary.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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/parser/cpdf_dictionary.h" 7 #include "core/fpdfapi/parser/cpdf_dictionary.h"
8 8
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 CPDF_Dictionary* CPDF_Dictionary::AsDictionary() { 52 CPDF_Dictionary* CPDF_Dictionary::AsDictionary() {
53 return this; 53 return this;
54 } 54 }
55 55
56 const CPDF_Dictionary* CPDF_Dictionary::AsDictionary() const { 56 const CPDF_Dictionary* CPDF_Dictionary::AsDictionary() const {
57 return this; 57 return this;
58 } 58 }
59 59
60 CPDF_Object* CPDF_Dictionary::Clone() const { 60 std::unique_ptr<CPDF_Object> CPDF_Dictionary::Clone() const {
61 return CloneObjectNonCyclic(false); 61 return CloneObjectNonCyclic(false);
62 } 62 }
63 63
64 CPDF_Object* CPDF_Dictionary::CloneNonCyclic( 64 std::unique_ptr<CPDF_Object> CPDF_Dictionary::CloneNonCyclic(
65 bool bDirect, 65 bool bDirect,
66 std::set<const CPDF_Object*>* pVisited) const { 66 std::set<const CPDF_Object*>* pVisited) const {
67 pVisited->insert(this); 67 pVisited->insert(this);
68 CPDF_Dictionary* pCopy = new CPDF_Dictionary(m_pPool); 68 auto pCopy = pdfium::MakeUnique<CPDF_Dictionary>(m_pPool);
69 for (const auto& it : *this) { 69 for (const auto& it : *this) {
70 CPDF_Object* value = it.second; 70 CPDF_Object* value = it.second;
71 if (!pdfium::ContainsKey(*pVisited, value)) { 71 if (!pdfium::ContainsKey(*pVisited, value)) {
72 pCopy->m_Map.insert( 72 pCopy->m_Map.insert(std::make_pair(
73 std::make_pair(it.first, value->CloneNonCyclic(bDirect, pVisited))); 73 it.first, value->CloneNonCyclic(bDirect, pVisited).release()));
74 } 74 }
75 } 75 }
76 return pCopy; 76 return std::unique_ptr<CPDF_Object>(std::move(pCopy));
Lei Zhang 2016/11/08 18:55:43 I saw you had green trybots on patch set 3, but yo
Tom Sepez 2016/11/09 18:20:46 It appears to be necessary for android, which had
77 } 77 }
78 78
79 CPDF_Object* CPDF_Dictionary::GetObjectFor(const CFX_ByteString& key) const { 79 CPDF_Object* CPDF_Dictionary::GetObjectFor(const CFX_ByteString& key) const {
80 auto it = m_Map.find(key); 80 auto it = m_Map.find(key);
81 return it != m_Map.end() ? it->second : nullptr; 81 return it != m_Map.end() ? it->second : nullptr;
82 } 82 }
83 83
84 CPDF_Object* CPDF_Dictionary::GetDirectObjectFor( 84 CPDF_Object* CPDF_Dictionary::GetDirectObjectFor(
85 const CFX_ByteString& key) const { 85 const CFX_ByteString& key) const {
86 CPDF_Object* p = GetObjectFor(key); 86 CPDF_Object* p = GetObjectFor(key);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 pArray->AddNumber(matrix.c); 277 pArray->AddNumber(matrix.c);
278 pArray->AddNumber(matrix.d); 278 pArray->AddNumber(matrix.d);
279 pArray->AddNumber(matrix.e); 279 pArray->AddNumber(matrix.e);
280 pArray->AddNumber(matrix.f); 280 pArray->AddNumber(matrix.f);
281 SetFor(key, pArray); 281 SetFor(key, pArray);
282 } 282 }
283 283
284 CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) { 284 CFX_ByteString CPDF_Dictionary::MaybeIntern(const CFX_ByteString& str) {
285 return m_pPool ? m_pPool->Intern(str) : str; 285 return m_pPool ? m_pPool->Intern(str) : str;
286 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698