From e51621d23d333c6d5d0279f5da30fcfd16d5ef9b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 11 Aug 2020 17:08:27 +0200 Subject: use unique_ptr for SvxSearchItem in ScGlobal Change-Id: I45f5d2bb699ef8cc6f32995bf15c2bf9095704fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100557 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/inc/global.hxx | 2 +- sc/source/core/data/global.cxx | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'sc') diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 31c26e8f2db9..bc576c9528ff 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -502,7 +502,7 @@ namespace utl { class ScGlobal { - static SvxSearchItem* pSearchItem; + static std::unique_ptr xSearchItem; static ScAutoFormat* pAutoFormat; static std::atomic pLegacyFuncCollection; static std::atomic pAddInCollection; diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index 02697c0eb84b..f8b87ba369ae 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -72,7 +72,7 @@ #include tools::SvRef ScGlobal::xDrawClipDocShellRef; -SvxSearchItem* ScGlobal::pSearchItem = nullptr; +std::unique_ptr ScGlobal::xSearchItem; ScAutoFormat* ScGlobal::pAutoFormat = nullptr; std::atomic ScGlobal::pLegacyFuncCollection(nullptr); std::atomic ScGlobal::pAddInCollection(nullptr); @@ -214,23 +214,22 @@ bool ScGlobal::CheckWidthInvalidate( bool& bNumFormatChanged, const SvxSearchItem& ScGlobal::GetSearchItem() { assert(!bThreadedGroupCalcInProgress); - if (!pSearchItem) + if (!xSearchItem) { - pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM ); - pSearchItem->SetAppFlag( SvxSearchApp::CALC ); + xSearchItem.reset(new SvxSearchItem( SID_SEARCH_ITEM )); + xSearchItem->SetAppFlag( SvxSearchApp::CALC ); } - return *pSearchItem; + return *xSearchItem; } void ScGlobal::SetSearchItem( const SvxSearchItem& rNew ) { assert(!bThreadedGroupCalcInProgress); // FIXME: An assignment operator would be nice here - delete pSearchItem; - pSearchItem = rNew.Clone(); + xSearchItem.reset(rNew.Clone()); - pSearchItem->SetWhich( SID_SEARCH_ITEM ); - pSearchItem->SetAppFlag( SvxSearchApp::CALC ); + xSearchItem->SetWhich( SID_SEARCH_ITEM ); + xSearchItem->SetAppFlag( SvxSearchApp::CALC ); } void ScGlobal::ClearAutoFormat() @@ -529,7 +528,7 @@ void ScGlobal::Clear() theAddInAsyncTbl.clear(); ExitExternalFunc(); ClearAutoFormat(); - DELETEZ(pSearchItem); + xSearchItem.reset(); delete pLegacyFuncCollection.load(); pLegacyFuncCollection = nullptr; delete pAddInCollection.load(); pAddInCollection = nullptr; xUserList.reset(); -- cgit