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/fde_render.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'xfa/fde/fde_render.cpp') diff --git a/xfa/fde/fde_render.cpp b/xfa/fde/fde_render.cpp index 7c989a0c6b..074a851e9f 100644 --- a/xfa/fde/fde_render.cpp +++ b/xfa/fde/fde_render.cpp @@ -16,11 +16,9 @@ CFDE_RenderContext::CFDE_RenderContext() : m_eStatus(FDE_RENDERSTATUS_Reset), m_pRenderDevice(nullptr), - m_pBrush(nullptr), m_Transform(), m_pCharPos(nullptr), - m_iCharPosCount(0), - m_pIterator(nullptr) { + m_iCharPosCount(0) { m_Transform.SetIdentity(); } @@ -42,7 +40,7 @@ FX_BOOL CFDE_RenderContext::StartRender(CFDE_RenderDevice* pRenderDevice, m_pRenderDevice = pRenderDevice; m_Transform = tmDoc2Device; if (!m_pIterator) - m_pIterator = new CFDE_VisualSetIterator; + m_pIterator.reset(new CFDE_VisualSetIterator); return m_pIterator->AttachCanvas(pCanvasSet) && m_pIterator->FilterObjects(); } @@ -101,12 +99,8 @@ void CFDE_RenderContext::StopRender() { m_eStatus = FDE_RENDERSTATUS_Reset; m_pRenderDevice = nullptr; m_Transform.SetIdentity(); - if (m_pIterator) { - m_pIterator->Release(); - m_pIterator = nullptr; - } - delete m_pBrush; - m_pBrush = nullptr; + m_pIterator.reset(); + m_pBrush.reset(); FX_Free(m_pCharPos); m_pCharPos = nullptr; m_iCharPosCount = 0; @@ -126,7 +120,7 @@ void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet, return; if (!m_pBrush) - m_pBrush = new CFDE_Brush; + m_pBrush.reset(new CFDE_Brush); if (!m_pCharPos) m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, iCount); @@ -142,8 +136,8 @@ void CFDE_RenderContext::RenderText(IFDE_TextSet* pTextSet, m_pBrush->SetColor(dwColor); FDE_HDEVICESTATE hState; FX_BOOL bClip = ApplyClip(pTextSet, hText, hState); - m_pRenderDevice->DrawString(m_pBrush, pFont, m_pCharPos, iCount, fFontSize, - &m_Transform); + m_pRenderDevice->DrawString(m_pBrush.get(), pFont, m_pCharPos, iCount, + fFontSize, &m_Transform); if (bClip) RestoreClip(hState); } -- cgit v1.2.3