diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-09-24 11:48:58 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-09-24 16:24:34 +0200 |
commit | 8792cf693dba3e05ed72a353685bc99d0d34c250 (patch) | |
tree | 099d6fc4234b73d173f831068f2a0a1b5d21c333 /sc | |
parent | e69ca434253d3278975078600f8a77291d97b9fc (diff) |
no need to allocate this SfxItemSet on the heap
Change-Id: I651d6091db543ebc958f888598edd2cdef4df43a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122574
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/inc/undostyl.hxx | 6 | ||||
-rw-r--r-- | sc/source/ui/undo/undostyl.cxx | 13 |
2 files changed, 12 insertions, 7 deletions
diff --git a/sc/source/ui/inc/undostyl.hxx b/sc/source/ui/inc/undostyl.hxx index 6ea88d0d9550..a4b3a7f44f76 100644 --- a/sc/source/ui/inc/undostyl.hxx +++ b/sc/source/ui/inc/undostyl.hxx @@ -20,7 +20,9 @@ #pragma once #include <memory> +#include <optional> #include <svl/style.hxx> +#include <svl/itemset.hxx> #include "undobase.hxx" class ScDocShell; @@ -30,7 +32,7 @@ class ScStyleSaveData private: OUString aName; OUString aParent; - std::unique_ptr<SfxItemSet> xItems; + std::optional<SfxItemSet> moItems; public: ScStyleSaveData(); @@ -41,7 +43,7 @@ public: const OUString& GetName() const { return aName; } const OUString& GetParent() const { return aParent; } - const SfxItemSet* GetItems() const { return xItems.get(); } + const std::optional<SfxItemSet>& GetItems() const { return moItems; } }; class ScUndoModifyStyle: public ScSimpleUndo diff --git a/sc/source/ui/undo/undostyl.cxx b/sc/source/ui/undo/undostyl.cxx index f110d0190051..a9d47feec685 100644 --- a/sc/source/ui/undo/undostyl.cxx +++ b/sc/source/ui/undo/undostyl.cxx @@ -41,8 +41,8 @@ ScStyleSaveData::ScStyleSaveData( const ScStyleSaveData& rOther ) : aName( rOther.aName ), aParent( rOther.aParent ) { - if (rOther.xItems) - xItems.reset(new SfxItemSet(*rOther.xItems)); + if (rOther.moItems) + moItems.emplace(*rOther.moItems); } ScStyleSaveData& ScStyleSaveData::operator=( const ScStyleSaveData& rOther ) @@ -51,7 +51,10 @@ ScStyleSaveData& ScStyleSaveData::operator=( const ScStyleSaveData& rOther ) { aName = rOther.aName; aParent = rOther.aParent; - xItems.reset(rOther.xItems ? new SfxItemSet(*rOther.xItems) : nullptr); + if (rOther.moItems) + moItems.emplace(*rOther.moItems); + else + moItems.reset(); } return *this; } @@ -62,7 +65,7 @@ void ScStyleSaveData::InitFromStyle( const SfxStyleSheetBase* pSource ) { aName = pSource->GetName(); aParent = pSource->GetParent(); - xItems.reset(new SfxItemSet(const_cast<SfxStyleSheetBase*>(pSource)->GetItemSet())); + moItems.emplace(const_cast<SfxStyleSheetBase*>(pSource)->GetItemSet()); } else *this = ScStyleSaveData(); // empty @@ -157,7 +160,7 @@ void ScUndoModifyStyle::DoChange( ScDocShell* pDocSh, const OUString& rName, pStyle->SetParent( aNewParent ); SfxItemSet& rStyleSet = pStyle->GetItemSet(); - const SfxItemSet* pNewSet = rData.GetItems(); + const std::optional<SfxItemSet>& pNewSet = rData.GetItems(); OSL_ENSURE( pNewSet, "no ItemSet for style" ); if (pNewSet) rStyleSet.Set( *pNewSet, false ); |