From c757d9a6f90bb879ce2cdd4a756b7b0e1885eb25 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 23 Jan 2017 11:01:42 -0800 Subject: Remove some |void Release() { delete this; }| anti-pattern. m_pSyntaxParser was unused. Review-Url: https://codereview.chromium.org/2646203002 --- xfa/fde/xml/fde_xml_imp.cpp | 39 ++++++---------------------------- xfa/fde/xml/fde_xml_imp.h | 8 ------- xfa/fxfa/parser/cxfa_node.cpp | 8 +++---- xfa/fxfa/parser/cxfa_simple_parser.cpp | 2 +- xfa/fxfa/parser/cxfa_xml_parser.h | 3 +-- 5 files changed, 11 insertions(+), 49 deletions(-) diff --git a/xfa/fde/xml/fde_xml_imp.cpp b/xfa/fde/xml/fde_xml_imp.cpp index 2bdaf5155f..e54b4167f6 100644 --- a/xfa/fde/xml/fde_xml_imp.cpp +++ b/xfa/fde/xml/fde_xml_imp.cpp @@ -84,10 +84,6 @@ CFDE_XMLNode::CFDE_XMLNode() m_pPrior(nullptr), m_pNext(nullptr) {} -void CFDE_XMLNode::Release() { - delete this; -} - FDE_XMLNODETYPE CFDE_XMLNode::GetType() const { return FDE_XMLNODE_Unknown; } @@ -99,9 +95,9 @@ CFDE_XMLNode::~CFDE_XMLNode() { void CFDE_XMLNode::DeleteChildren() { CFDE_XMLNode* pChild = m_pChild; while (pChild) { - CFDE_XMLNode* pTemp = pChild->m_pNext; - pChild->Release(); - pChild = pTemp; + CFDE_XMLNode* pNext = pChild->m_pNext; + delete pChild; + pChild = pNext; } m_pChild = nullptr; } @@ -529,10 +525,6 @@ CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) ASSERT(m_wsTarget.GetLength() > 0); } -void CFDE_XMLInstruction::Release() { - delete this; -} - FDE_XMLNODETYPE CFDE_XMLInstruction::GetType() const { return FDE_XMLNODE_Instruction; } @@ -687,10 +679,6 @@ CFDE_XMLElement::CFDE_XMLElement(const CFX_WideString& wsTag) CFDE_XMLElement::~CFDE_XMLElement() {} -void CFDE_XMLElement::Release() { - delete this; -} - FDE_XMLNODETYPE CFDE_XMLElement::GetType() const { return FDE_XMLNODE_Element; } @@ -899,10 +887,6 @@ void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) : CFDE_XMLNode(), m_wsText(wsText) {} -void CFDE_XMLText::Release() { - delete this; -} - FDE_XMLNODETYPE CFDE_XMLText::GetType() const { return FDE_XMLNODE_Text; } @@ -917,10 +901,6 @@ CFDE_XMLText::~CFDE_XMLText() {} CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} -void CFDE_XMLCharData::Release() { - delete this; -} - FDE_XMLNODETYPE CFDE_XMLCharData::GetType() const { return FDE_XMLNODE_CharData; } @@ -932,8 +912,7 @@ CFDE_XMLNode* CFDE_XMLCharData::Clone(bool bRecursive) { CFDE_XMLCharData::~CFDE_XMLCharData() {} -CFDE_XMLDoc::CFDE_XMLDoc() - : m_pRoot(nullptr), m_pSyntaxParser(nullptr), m_pXMLParser(nullptr) { +CFDE_XMLDoc::CFDE_XMLDoc() : m_pRoot(nullptr) { Reset(true); CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); m_pRoot->InsertChildNode(pXML); @@ -952,20 +931,14 @@ void CFDE_XMLDoc::Reset(bool bInitRoot) { else m_pRoot = new CFDE_XMLNode; } else { - if (m_pRoot) { - m_pRoot->Release(); - m_pRoot = nullptr; - } + delete m_pRoot; + m_pRoot = nullptr; } ReleaseParser(); } void CFDE_XMLDoc::ReleaseParser() { m_pXMLParser.reset(); - if (m_pSyntaxParser) { - m_pSyntaxParser->Release(); - m_pSyntaxParser = nullptr; - } } bool CFDE_XMLDoc::LoadXML(std::unique_ptr pXMLParser) { diff --git a/xfa/fde/xml/fde_xml_imp.h b/xfa/fde/xml/fde_xml_imp.h index 49c5c51f77..41e84bad17 100644 --- a/xfa/fde/xml/fde_xml_imp.h +++ b/xfa/fde/xml/fde_xml_imp.h @@ -44,7 +44,6 @@ class CFDE_XMLNode { CFDE_XMLNode(); virtual ~CFDE_XMLNode(); - virtual void Release(); virtual FDE_XMLNODETYPE GetType() const; virtual CFDE_XMLNode* Clone(bool bRecursive); @@ -79,7 +78,6 @@ class CFDE_XMLInstruction : public CFDE_XMLNode { ~CFDE_XMLInstruction() override; // CFDE_XMLNode - void Release() override; FDE_XMLNODETYPE GetType() const override; CFDE_XMLNode* Clone(bool bRecursive) override; @@ -115,7 +113,6 @@ class CFDE_XMLElement : public CFDE_XMLNode { ~CFDE_XMLElement() override; // CFDE_XMLNode - void Release() override; FDE_XMLNODETYPE GetType() const override; CFDE_XMLNode* Clone(bool bRecursive) override; @@ -157,7 +154,6 @@ class CFDE_XMLText : public CFDE_XMLNode { ~CFDE_XMLText() override; // CFDE_XMLNode - void Release() override; FDE_XMLNODETYPE GetType() const override; CFDE_XMLNode* Clone(bool bRecursive) override; @@ -178,7 +174,6 @@ class CFDE_XMLCharData : public CFDE_XMLDeclaration { explicit CFDE_XMLCharData(const CFX_WideString& wsCData); ~CFDE_XMLCharData() override; - void Release() override; FDE_XMLNODETYPE GetType() const override; CFDE_XMLNode* Clone(bool bRecursive) override; @@ -210,7 +205,6 @@ class CFDE_XMLDoc { CFX_RetainPtr m_pStream; int32_t m_iStatus; CFDE_XMLNode* m_pRoot; - CFDE_XMLSyntaxParser* m_pSyntaxParser; std::unique_ptr m_pXMLParser; }; @@ -227,7 +221,6 @@ class CFDE_BlockBuffer { bool InitBuffer(int32_t iBufferSize = 1024 * 1024); bool IsInitialized() { return m_iBufferSize / m_iAllocStep >= 1; } - void ReleaseBuffer() { delete this; } FX_WCHAR* GetAvailableBlock(int32_t& iIndexInBlock); inline int32_t GetAllocStep() const { return m_iAllocStep; } inline int32_t& GetDataLengthRef() { return m_iDataLength; } @@ -261,7 +254,6 @@ class CFDE_XMLSyntaxParser { CFDE_XMLSyntaxParser(); ~CFDE_XMLSyntaxParser(); - void Release() { delete this; } void Init(const CFX_RetainPtr& pStream, int32_t iXMLPlaneSize, int32_t iTextDataSize = 256); diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index bc2a10c08b..5411443e6a 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -511,7 +511,7 @@ CXFA_Node::~CXFA_Node() { pNode = pNext; } if (m_pXMLNode && IsOwnXMLNode()) - m_pXMLNode->Release(); + delete m_pXMLNode; } CXFA_Node* CXFA_Node::Clone(bool bRecursive) { @@ -1406,10 +1406,8 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { } pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); } else { - if (pFakeXMLRoot) { - pFakeXMLRoot->Release(); - pFakeXMLRoot = nullptr; - } + delete pFakeXMLRoot; + pFakeXMLRoot = nullptr; } } diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index 9f6fef9c1f..2417afaf1e 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -747,7 +747,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_Element::DataGroup); if (!pNode) { if (pDataXMLNode != pXMLDocumentNode) - pDataXMLNode->Release(); + delete pDataXMLNode; return nullptr; } CFX_WideString wsLocalName; diff --git a/xfa/fxfa/parser/cxfa_xml_parser.h b/xfa/fxfa/parser/cxfa_xml_parser.h index e49a9dd127..9393b7e597 100644 --- a/xfa/fxfa/parser/cxfa_xml_parser.h +++ b/xfa/fxfa/parser/cxfa_xml_parser.h @@ -32,8 +32,7 @@ class CXFA_XMLParser : public IFDE_XMLParser { protected: CFDE_XMLNode* m_pRoot; CFX_RetainPtr m_pStream; - std::unique_ptr> - m_pParser; + std::unique_ptr m_pParser; CFDE_XMLNode* m_pParent; CFDE_XMLNode* m_pChild; CFX_StackTemplate m_NodeStack; -- cgit v1.2.3