From f74ad998d2e8d2636fb25e94823946a3b151e34e Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 11 May 2016 10:26:05 -0700 Subject: Replace some calls to Release() with direct delete, part 1. Searching for the anti-pattern: void Release() { delete this; } We must be explicit on the ownership model. Add unique_ptrs as a result. Review-Url: https://codereview.chromium.org/1960673003 --- xfa/fde/css/fde_cssstylesheet.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'xfa/fde/css/fde_cssstylesheet.cpp') diff --git a/xfa/fde/css/fde_cssstylesheet.cpp b/xfa/fde/css/fde_cssstylesheet.cpp index af6872bbaa..b07031c354 100644 --- a/xfa/fde/css/fde_cssstylesheet.cpp +++ b/xfa/fde/css/fde_cssstylesheet.cpp @@ -6,6 +6,8 @@ #include "xfa/fde/css/fde_cssstylesheet.h" +#include + #include "xfa/fde/css/fde_cssdatatable.h" #include "xfa/fde/css/fde_csssyntax.h" #include "xfa/fgas/crt/fgas_codepage.h" @@ -120,32 +122,33 @@ int32_t CFDE_CSSStyleSheet::CountRules() const { IFDE_CSSRule* CFDE_CSSStyleSheet::GetRule(int32_t index) { return m_RuleArray.GetAt(index); } + FX_BOOL CFDE_CSSStyleSheet::LoadFromStream(const CFX_WideString& szUrl, IFX_Stream* pStream, uint16_t wCodePage) { - CFDE_CSSSyntaxParser* pSyntax = new CFDE_CSSSyntaxParser; - if (pStream->GetCodePage() != wCodePage) { + std::unique_ptr pSyntax(new CFDE_CSSSyntaxParser); + if (pStream->GetCodePage() != wCodePage) pStream->SetCodePage(wCodePage); - } - FX_BOOL bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax); - pSyntax->Release(); + + FX_BOOL bRet = pSyntax->Init(pStream, 4096) && LoadFromSyntax(pSyntax.get()); m_wCodePage = wCodePage; m_szUrl = szUrl; return bRet; } + FX_BOOL CFDE_CSSStyleSheet::LoadFromBuffer(const CFX_WideString& szUrl, const FX_WCHAR* pBuffer, int32_t iBufSize, uint16_t wCodePage) { ASSERT(pBuffer && iBufSize > 0); - - CFDE_CSSSyntaxParser* pSyntax = new CFDE_CSSSyntaxParser; - FX_BOOL bRet = pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax); - pSyntax->Release(); + std::unique_ptr pSyntax(new CFDE_CSSSyntaxParser); + FX_BOOL bRet = + pSyntax->Init(pBuffer, iBufSize) && LoadFromSyntax(pSyntax.get()); m_wCodePage = wCodePage; m_szUrl = szUrl; return bRet; } + FX_BOOL CFDE_CSSStyleSheet::LoadFromSyntax(CFDE_CSSSyntaxParser* pSyntax) { Reset(); m_pAllocator = IFX_MemoryAllocator::Create(FX_ALLOCTYPE_Static, 1024, 0); -- cgit v1.2.3