diff options
author | Nicolas Pena <npm@chromium.org> | 2017-04-05 16:34:50 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-05 21:45:05 +0000 |
commit | 0b18e1599dc9d07355c4ab6a069de33a536f7ba8 (patch) | |
tree | bb61d776d30dc4906f25ba566be934958ef7c34e | |
parent | 480f62b8350f17a398cbf4f02b76b4368a62dce6 (diff) | |
download | pdfium-chromium/3064.tar.xz |
Use unique_ptr in the children of CFieldTree::Nodechromium/3064
Change-Id: I149718bbdb7195223012150d6162d73cbeb3b8cc
Reviewed-on: https://pdfium-review.googlesource.com/3813
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Nicolás Peña <npm@chromium.org>
-rw-r--r-- | core/fpdfdoc/cpdf_interform.cpp | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 0af050d0b2..1192e6e556 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -397,12 +397,14 @@ class CFieldTree { explicit Node(const CFX_WideString& short_name) : m_ShortName(short_name) {} ~Node() {} - void AddChildNode(Node* pNode) { m_Children.push_back(pNode); } + void AddChildNode(std::unique_ptr<Node> pNode) { + m_Children.push_back(std::move(pNode)); + } size_t GetChildrenCount() const { return m_Children.size(); } - Node* GetChildAt(size_t i) { return m_Children[i]; } - const Node* GetChildAt(size_t i) const { return m_Children[i]; } + Node* GetChildAt(size_t i) { return m_Children[i].get(); } + const Node* GetChildAt(size_t i) const { return m_Children[i].get(); } CPDF_FormField* GetFieldAtIndex(size_t index) { size_t nFieldsToGo = index; @@ -448,7 +450,7 @@ class CFieldTree { return count; } - std::vector<Node*> m_Children; + std::vector<std::unique_ptr<Node>> m_Children; CFX_WideString m_ShortName; std::unique_ptr<CPDF_FormField> m_pField; }; @@ -459,11 +461,9 @@ class CFieldTree { bool SetField(const CFX_WideString& full_name, std::unique_ptr<CPDF_FormField> pField); CPDF_FormField* GetField(const CFX_WideString& full_name); - void RemoveAll(); Node* FindNode(const CFX_WideString& full_name); Node* AddChild(Node* pParent, const CFX_WideString& short_name); - void RemoveNode(Node* pNode, int nLevel = 0); Node* Lookup(Node* pParent, const CFX_WideString& short_name); @@ -472,29 +472,17 @@ class CFieldTree { CFieldTree::CFieldTree() {} -CFieldTree::~CFieldTree() { - RemoveAll(); -} +CFieldTree::~CFieldTree() {} CFieldTree::Node* CFieldTree::AddChild(Node* pParent, const CFX_WideString& short_name) { if (!pParent) return nullptr; - Node* pNode = new Node(short_name); - pParent->AddChildNode(pNode); - return pNode; -} - -void CFieldTree::RemoveNode(Node* pNode, int nLevel) { - if (!pNode) - return; - - if (nLevel <= nMaxRecursion) { - for (size_t i = 0; i < pNode->GetChildrenCount(); ++i) - RemoveNode(pNode->GetChildAt(i), nLevel + 1); - } - delete pNode; + auto pNew = pdfium::MakeUnique<Node>(short_name); + Node* pChild = pNew.get(); + pParent->AddChildNode(std::move(pNew)); + return pChild; } CFieldTree::Node* CFieldTree::Lookup(Node* pParent, @@ -510,11 +498,6 @@ CFieldTree::Node* CFieldTree::Lookup(Node* pParent, return nullptr; } -void CFieldTree::RemoveAll() { - for (size_t i = 0; i < m_Root.GetChildrenCount(); ++i) - RemoveNode(m_Root.GetChildAt(i)); -} - bool CFieldTree::SetField(const CFX_WideString& full_name, std::unique_ptr<CPDF_FormField> pField) { if (full_name.IsEmpty()) |