From d1dfb7d56137ea62d6f3cdfb07f3ee841eb28f9e Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 31 May 2021 11:11:30 +0200 Subject: no need to allocate these separately Change-Id: I9464fbcc1af966755cc4eb8fe0beead4638848ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116479 Tested-by: Jenkins Reviewed-by: Noel Grandin --- framework/inc/classes/protocolhandlercache.hxx | 7 ++++--- .../source/fwi/classes/protocolhandlercache.cxx | 24 +++++++++++----------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/framework/inc/classes/protocolhandlercache.hxx b/framework/inc/classes/protocolhandlercache.hxx index 78a3449f8aa9..d29ba6795248 100644 --- a/framework/inc/classes/protocolhandlercache.hxx +++ b/framework/inc/classes/protocolhandlercache.hxx @@ -20,6 +20,7 @@ #pragma once #include +#include #include @@ -90,9 +91,9 @@ class HandlerCache final private: /// list of all registered handler registered by her uno implementation names - static std::unique_ptr s_pHandler; + static std::optional s_pHandler; /// maps URL pattern to handler names - static std::unique_ptr s_pPattern; + static std::optional s_pPattern; /// informs about config updates static HandlerCFGAccess* s_pConfig; /// ref count to construct/destruct internal member lists on demand by using singleton mechanism @@ -107,7 +108,7 @@ class HandlerCache final bool search( const OUString& sURL, ProtocolHandler* pReturn ) const; bool search( const css::util::URL& aURL, ProtocolHandler* pReturn ) const; - void takeOver(std::unique_ptr pHandler, std::unique_ptr pPattern); + void takeOver(HandlerHash aHandler, PatternHash aPattern); }; /** diff --git a/framework/source/fwi/classes/protocolhandlercache.cxx b/framework/source/fwi/classes/protocolhandlercache.cxx index 9288536480d9..1879554c7bed 100644 --- a/framework/source/fwi/classes/protocolhandlercache.cxx +++ b/framework/source/fwi/classes/protocolhandlercache.cxx @@ -68,8 +68,8 @@ PatternHash::const_iterator findPatternKey(PatternHash const * hash, const OUStr That means it use two static member list to hold all necessary information and a ref count mechanism to create/destroy it on demand. */ -std::unique_ptr HandlerCache::s_pHandler; -std::unique_ptr HandlerCache::s_pPattern; +std::optional HandlerCache::s_pHandler; +std::optional HandlerCache::s_pPattern; sal_Int32 HandlerCache::m_nRefCount = 0; HandlerCFGAccess* HandlerCache::s_pConfig = nullptr; @@ -86,8 +86,8 @@ HandlerCache::HandlerCache() if (m_nRefCount==0) { - s_pHandler.reset(new HandlerHash); - s_pPattern.reset(new PatternHash); + s_pHandler.emplace(); + s_pPattern.emplace(); s_pConfig = new HandlerCFGAccess(PACKAGENAME_PROTOCOLHANDLER); s_pConfig->read(*s_pHandler, *s_pPattern); s_pConfig->setCache(this); @@ -129,7 +129,7 @@ bool HandlerCache::search( const OUString& sURL, ProtocolHandler* pReturn ) cons SolarMutexGuard aGuard; - PatternHash::const_iterator pItem = findPatternKey(s_pPattern.get(), sURL); + PatternHash::const_iterator pItem = findPatternKey(s_pPattern ? &*s_pPattern : nullptr, sURL); if (pItem != s_pPattern->end()) { *pReturn = (*s_pHandler)[pItem->second]; @@ -150,12 +150,12 @@ bool HandlerCache::search( const css::util::URL& aURL, ProtocolHandler* pReturn return search( aURL.Complete, pReturn ); } -void HandlerCache::takeOver(std::unique_ptr pHandler, std::unique_ptr pPattern) +void HandlerCache::takeOver(HandlerHash aHandler, PatternHash aPattern) { SolarMutexGuard aGuard; - s_pHandler = std::move(pHandler); - s_pPattern = std::move(pPattern); + s_pHandler = std::move(aHandler); + s_pPattern = std::move(aPattern); } /** @@ -240,12 +240,12 @@ void HandlerCFGAccess::read( HandlerHash& rHandlerHash, PatternHash& rPatternHas void HandlerCFGAccess::Notify(const css::uno::Sequence< OUString >& /*lPropertyNames*/) { - std::unique_ptr pHandler(new HandlerHash); - std::unique_ptr pPattern(new PatternHash); + HandlerHash aHandler; + PatternHash aPattern; - read(*pHandler, *pPattern); + read(aHandler, aPattern); if (m_pCache) - m_pCache->takeOver(std::move(pHandler), std::move(pPattern)); + m_pCache->takeOver(std::move(aHandler), std::move(aPattern)); } void HandlerCFGAccess::ImplCommit() -- cgit v1.2.3