From 9ca2b09126b80c03655f0eee1f02e1b2d0a18230 Mon Sep 17 00:00:00 2001 From: weili Date: Thu, 21 Jul 2016 12:26:18 -0700 Subject: Remove the use of handler array in CPDFSDK_AnnotHandlerMgr Use map to store and manage the handlers directly instead of needing an extra array. Review-Url: https://codereview.chromium.org/2166953005 --- fpdfsdk/fsdk_annothandler.cpp | 20 +++----------------- fpdfsdk/include/fsdk_annothandler.h | 6 +++--- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/fpdfsdk/fsdk_annothandler.cpp b/fpdfsdk/fsdk_annothandler.cpp index 2185562668..f7dd531f35 100644 --- a/fpdfsdk/fsdk_annothandler.cpp +++ b/fpdfsdk/fsdk_annothandler.cpp @@ -40,32 +40,18 @@ CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { #endif // PDF_ENABLE_XFA } -CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { - for (int i = 0; i < m_Handlers.GetSize(); i++) { - IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); - delete pHandler; - } - m_Handlers.RemoveAll(); - m_mapType2Handler.clear(); -} +CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {} void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( IPDFSDK_AnnotHandler* pAnnotHandler) { ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); - m_Handlers.Add(pAnnotHandler); - m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler; + m_mapType2Handler[pAnnotHandler->GetType()].reset(pAnnotHandler); } void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( IPDFSDK_AnnotHandler* pAnnotHandler) { m_mapType2Handler.erase(pAnnotHandler->GetType()); - for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { - if (m_Handlers.GetAt(i) == pAnnotHandler) { - m_Handlers.RemoveAt(i); - break; - } - } } CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, @@ -139,7 +125,7 @@ IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( const CFX_ByteString& sType) const { auto it = m_mapType2Handler.find(sType); - return it != m_mapType2Handler.end() ? it->second : nullptr; + return it != m_mapType2Handler.end() ? it->second.get() : nullptr; } void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, diff --git a/fpdfsdk/include/fsdk_annothandler.h b/fpdfsdk/include/fsdk_annothandler.h index 179843da8a..1e25538a32 100644 --- a/fpdfsdk/include/fsdk_annothandler.h +++ b/fpdfsdk/include/fsdk_annothandler.h @@ -8,6 +8,7 @@ #define FPDFSDK_INCLUDE_FSDK_ANNOTHANDLER_H_ #include +#include #include #include "core/fxcrt/include/fx_basic.h" @@ -314,7 +315,6 @@ class CPDFSDK_XFAAnnotHandler : public IPDFSDK_AnnotHandler { }; #endif // PDF_ENABLE_XFA -#define CBA_AnnotHandlerArray CFX_ArrayTemplate class CPDFSDK_AnnotHandlerMgr { public: // Destroy the handler @@ -409,8 +409,8 @@ class CPDFSDK_AnnotHandlerMgr { CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, FX_BOOL bNext); private: - CBA_AnnotHandlerArray m_Handlers; - std::map m_mapType2Handler; + std::map> + m_mapType2Handler; CPDFDoc_Environment* m_pApp; }; -- cgit v1.2.3