[Libreoffice-commits] core.git: 2 commits - chart2/source cui/source dbaccess/source editeng/source forms/source include/svl reportdesign/source sc/source sd/source svl/source svx/source sw/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu May 9 06:49:01 UTC 2019


 chart2/source/controller/itemsetwrapper/GraphicPropertyItemConverter.cxx |    8 
 chart2/source/controller/itemsetwrapper/ItemConverter.cxx                |    2 
 cui/source/options/treeopt.cxx                                           |    3 
 cui/source/tabpages/border.cxx                                           |    4 
 cui/source/tabpages/page.cxx                                             |    2 
 cui/source/tabpages/paragrph.cxx                                         |    6 
 dbaccess/source/ui/misc/propertystorage.cxx                              |    2 
 editeng/source/editeng/editdoc.cxx                                       |    5 
 editeng/source/editeng/editview.cxx                                      |    3 
 forms/source/richtext/richtextimplcontrol.cxx                            |    4 
 forms/source/richtext/rtattributehandler.cxx                             |    9 -
 include/svl/itempool.hxx                                                 |    2 
 include/svl/itemset.hxx                                                  |   14 +
 reportdesign/source/ui/misc/UITools.cxx                                  |    5 
 sc/source/filter/excel/xlroot.cxx                                        |    9 -
 sc/source/filter/ftools/ftools.cxx                                       |    3 
 sc/source/filter/rtf/eeimpars.cxx                                        |   20 --
 sc/source/ui/Accessibility/AccessibleText.cxx                            |    9 -
 sc/source/ui/pagedlg/tphfedit.cxx                                        |    9 -
 sc/source/ui/unoobj/textuno.cxx                                          |    9 -
 sc/source/ui/view/formatsh.cxx                                           |    3 
 sc/source/ui/view/printfun.cxx                                           |    9 -
 sc/source/ui/view/viewutil.cxx                                           |    3 
 sd/source/ui/dlg/dlgolbul.cxx                                            |    3 
 sd/source/ui/func/fuolbull.cxx                                           |    3 
 sd/source/ui/func/futempl.cxx                                            |   14 -
 sd/source/ui/view/drtxtob.cxx                                            |    3 
 sd/source/ui/view/outlnvsh.cxx                                           |    2 
 sd/source/ui/view/viewshel.cxx                                           |    3 
 svl/source/items/itemset.cxx                                             |   87 +++++++---
 svl/source/items/poolcach.cxx                                            |    4 
 svx/source/dialog/hdft.cxx                                               |    2 
 svx/source/sdr/properties/itemsettools.cxx                               |    2 
 sw/source/core/doc/DocumentStylePoolManager.cxx                          |   20 +-
 sw/source/core/doc/doclay.cxx                                            |    6 
 sw/source/core/doc/poolfmt.cxx                                           |   10 -
 sw/source/core/doc/tblafmt.cxx                                           |   18 --
 sw/source/core/docnode/ndtbl.cxx                                         |    2 
 sw/source/core/tox/ToxTextGenerator.cxx                                  |    6 
 sw/source/core/unocore/unoframe.cxx                                      |    2 
 sw/source/core/unocore/unostyle.cxx                                      |    4 
 sw/source/filter/basflt/fltini.cxx                                       |    4 
 sw/source/filter/html/htmldrawreader.cxx                                 |    6 
 sw/source/filter/html/htmldrawwriter.cxx                                 |    4 
 sw/source/filter/ww8/wrtw8nds.cxx                                        |    5 
 sw/source/filter/ww8/ww8graf.cxx                                         |    8 
 sw/source/filter/ww8/ww8par6.cxx                                         |    2 
 sw/source/filter/xml/xmlitemi.cxx                                        |    2 
 sw/source/ui/chrdlg/numpara.cxx                                          |    4 
 sw/source/uibase/app/appopt.cxx                                          |   12 -
 sw/source/uibase/shells/annotsh.cxx                                      |    9 -
 sw/source/uibase/shells/basesh.cxx                                       |    3 
 sw/source/uibase/shells/drwtxtex.cxx                                     |    9 -
 sw/source/uibase/shells/tabsh.cxx                                        |    7 
 sw/source/uibase/shells/textsh1.cxx                                      |    3 
 sw/source/uibase/uiview/formatclipboard.cxx                              |    2 
 sw/source/uibase/uiview/viewstat.cxx                                     |   17 -
 sw/source/uibase/utlui/uitool.cxx                                        |    2 
 58 files changed, 198 insertions(+), 235 deletions(-)

New commits:
commit e0382c3ad7786910bc9aa81cf581798df0f2508c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed May 8 08:29:46 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu May 9 08:47:50 2019 +0200

    avoid copying when placing items into SfxItemSet
    
    Change-Id: I05c627f590e7794c1ba11b66021dc30aa3285eb0
    Reviewed-on: https://gerrit.libreoffice.org/71941
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/chart2/source/controller/itemsetwrapper/GraphicPropertyItemConverter.cxx b/chart2/source/controller/itemsetwrapper/GraphicPropertyItemConverter.cxx
index e709a0f397af..fa253a6830e3 100644
--- a/chart2/source/controller/itemsetwrapper/GraphicPropertyItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/GraphicPropertyItemConverter.cxx
@@ -295,7 +295,7 @@ void GraphicPropertyItemConverter::FillSpecialItem(
             std::unique_ptr<XLineDashItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
 
             if(pItemToPut)
-                 rOutItemSet.Put( *pItemToPut );
+                 rOutItemSet.Put( std::move(pItemToPut) );
             else
                 rOutItemSet.Put(aItem);
         }
@@ -321,7 +321,7 @@ void GraphicPropertyItemConverter::FillSpecialItem(
                 std::unique_ptr<XFillGradientItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
 
                 if(pItemToPut)
-                    rOutItemSet.Put( *pItemToPut );
+                    rOutItemSet.Put(std::move(pItemToPut) );
                 else
                     rOutItemSet.Put(aItem);
             }
@@ -347,7 +347,7 @@ void GraphicPropertyItemConverter::FillSpecialItem(
                 std::unique_ptr<XFillHatchItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
 
                 if(pItemToPut)
-                    rOutItemSet.Put( *pItemToPut );
+                    rOutItemSet.Put( std::move(pItemToPut) );
                 else
                     rOutItemSet.Put(aItem);
             }
@@ -368,7 +368,7 @@ void GraphicPropertyItemConverter::FillSpecialItem(
                 std::unique_ptr<XFillBitmapItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
 
                 if(pItemToPut)
-                    rOutItemSet.Put( *pItemToPut );
+                    rOutItemSet.Put( std::move(pItemToPut) );
                 else
                     rOutItemSet.Put(aItem);
             }
diff --git a/chart2/source/controller/itemsetwrapper/ItemConverter.cxx b/chart2/source/controller/itemsetwrapper/ItemConverter.cxx
index 6fd5ac749a1f..c0f7f0da3276 100644
--- a/chart2/source/controller/itemsetwrapper/ItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/ItemConverter.cxx
@@ -107,7 +107,7 @@ void ItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
                                 ))
                         {
                             pItem->SetWhich(nWhich);
-                            rOutItemSet.Put( *pItem );
+                            rOutItemSet.Put( std::move(pItem) );
                         }
                     }
                     catch( const beans::UnknownPropertyException &ex )
diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx
index 79ebf3644b14..6b8dac450be5 100644
--- a/cui/source/options/treeopt.cxx
+++ b/cui/source/options/treeopt.cxx
@@ -1191,8 +1191,7 @@ std::unique_ptr<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId
                 pRet->Put(aHyphen);
                 if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_AUTOSPELL_CHECK, pItem))
                 {
-                    std::unique_ptr<SfxPoolItem> pClone(pItem->Clone());
-                    pRet->Put(*pClone);
+                    pRet->Put(std::unique_ptr<SfxPoolItem>(pItem->Clone()));
                 }
                 else
                 {
diff --git a/cui/source/tabpages/border.cxx b/cui/source/tabpages/border.cxx
index 208d50f0cf55..a0449ef7379c 100644
--- a/cui/source/tabpages/border.cxx
+++ b/cui/source/tabpages/border.cxx
@@ -900,7 +900,7 @@ bool SvxBorderTabPage::FillItemSet( SfxItemSet* rCoreAttrs )
         {
             std::unique_ptr<SfxBoolItem> xNewItem(static_cast<SfxBoolItem*>(rCoreAttrs->Get(nMergeAdjacentBordersId).Clone()));
             xNewItem->SetValue(static_cast<bool>(nState));
-            rCoreAttrs->Put(*xNewItem);
+            rCoreAttrs->Put(std::move(xNewItem));
         }
         bAttrsChanged = true;
     }
@@ -915,7 +915,7 @@ bool SvxBorderTabPage::FillItemSet( SfxItemSet* rCoreAttrs )
         {
             std::unique_ptr<SfxBoolItem> xNewItem(static_cast<SfxBoolItem*>(rCoreAttrs->Get(nMergeWithNextId).Clone()));
             xNewItem->SetValue(static_cast<bool>(nState));
-            rCoreAttrs->Put(*xNewItem);
+            rCoreAttrs->Put(std::move(xNewItem));
         }
         bAttrsChanged = true;
     }
diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx
index e3c3b704efd9..a5e7269c224c 100644
--- a/cui/source/tabpages/page.cxx
+++ b/cui/source/tabpages/page.cxx
@@ -765,7 +765,7 @@ bool SvxPageDescPage::FillItemSet( SfxItemSet* rSet )
         std::unique_ptr<SfxBoolItem> pRegItem(static_cast<SfxBoolItem*>(rRegItem.Clone()));
         bool bCheck = m_xRegisterCB->get_active();
         pRegItem->SetValue(bCheck);
-        rSet->Put(*pRegItem);
+        rSet->Put(std::move(pRegItem));
         bModified = true;
         if(bCheck)
         {
diff --git a/cui/source/tabpages/paragrph.cxx b/cui/source/tabpages/paragrph.cxx
index 6c8cf7293f26..9c9bca1963c8 100644
--- a/cui/source/tabpages/paragrph.cxx
+++ b/cui/source/tabpages/paragrph.cxx
@@ -2238,7 +2238,7 @@ bool SvxAsianTabPage::FillItemSet( SfxItemSet* rSet )
         std::unique_ptr<SfxBoolItem> pNewItem(static_cast<SfxBoolItem*>(rSet->Get(
             pPool->GetWhich(SID_ATTR_PARA_SCRIPTSPACE)).Clone()));
         pNewItem->SetValue(m_xScriptSpaceCB->get_active());
-        rSet->Put(*pNewItem);
+        rSet->Put(std::move(pNewItem));
         bRet = true;
     }
     if (m_xHangingPunctCB->get_sensitive() && m_xHangingPunctCB->get_state_changed_from_saved())
@@ -2246,7 +2246,7 @@ bool SvxAsianTabPage::FillItemSet( SfxItemSet* rSet )
         std::unique_ptr<SfxBoolItem> pNewItem(static_cast<SfxBoolItem*>(rSet->Get(
             pPool->GetWhich(SID_ATTR_PARA_HANGPUNCTUATION)).Clone()));
         pNewItem->SetValue(m_xHangingPunctCB->get_active());
-        rSet->Put(*pNewItem);
+        rSet->Put(std::move(pNewItem));
         bRet = true;
     }
     if (m_xForbiddenRulesCB->get_sensitive() && m_xForbiddenRulesCB->get_state_changed_from_saved())
@@ -2254,7 +2254,7 @@ bool SvxAsianTabPage::FillItemSet( SfxItemSet* rSet )
         std::unique_ptr<SfxBoolItem> pNewItem(static_cast<SfxBoolItem*>(rSet->Get(
             pPool->GetWhich(SID_ATTR_PARA_FORBIDDEN_RULES)).Clone()));
         pNewItem->SetValue(m_xForbiddenRulesCB->get_active());
-        rSet->Put(*pNewItem);
+        rSet->Put(std::move(pNewItem));
         bRet = true;
     }
     return bRet;
diff --git a/dbaccess/source/ui/misc/propertystorage.cxx b/dbaccess/source/ui/misc/propertystorage.cxx
index 31204469db17..c3c504994236 100644
--- a/dbaccess/source/ui/misc/propertystorage.cxx
+++ b/dbaccess/source/ui/misc/propertystorage.cxx
@@ -60,7 +60,7 @@ namespace dbaui
                 std::unique_ptr< ITEMTYPE > pClone( pCloneItem);
                 assert(pClone.get());
                 pClone->SetValue( aValue );
-                _rSet.Put( *pClone );
+                _rSet.Put( std::move(pClone) );
                 return true;
             }
 
diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
index ef5964c822f5..c416f61125c9 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -901,12 +901,11 @@ void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const Map
                 std::unique_ptr<SfxPoolItem> pItem(rSource.Get( nSourceWhich ).Clone());
                 ConvertItem( pItem, eSourceUnit, eDestUnit );
                 pItem->SetWhich(nWhich);
-                rDest.Put( *pItem );
+                rDest.Put( std::move(pItem) );
             }
             else
             {
-                std::unique_ptr<SfxPoolItem> pNewItem(rSource.Get( nSourceWhich ).CloneSetWhich(nWhich));
-                rDest.Put( *pNewItem );
+                rDest.Put( rSource.Get( nSourceWhich ).CloneSetWhich(nWhich) );
             }
         }
     }
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 0e2dcfd55751..75624ea527d5 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -1378,8 +1378,7 @@ bool EditView::ChangeFontSize( bool bGrow, SfxItemSet& rSet, const FontList* pFo
             if( nHeight != static_cast<long>(aFontHeightItem.GetHeight()) )
             {
                 aFontHeightItem.SetHeight( nHeight );
-                std::unique_ptr<SfxPoolItem> pNewItem(aFontHeightItem.CloneSetWhich(*pWhich));
-                rSet.Put( *pNewItem );
+                rSet.Put( aFontHeightItem.CloneSetWhich(*pWhich) );
                 bRet = true;
             }
         }
diff --git a/forms/source/richtext/richtextimplcontrol.cxx b/forms/source/richtext/richtextimplcontrol.cxx
index 50f240aeae93..fb63c82bfc39 100644
--- a/forms/source/richtext/richtextimplcontrol.cxx
+++ b/forms/source/richtext/richtextimplcontrol.cxx
@@ -228,9 +228,7 @@ namespace frm
         WhichId nNormalizedWhichId = _rScriptSetItem.GetItemSet().GetPool()->GetWhich( _rScriptSetItem.Which() );
         if ( pNormalizedItem )
         {
-            std::unique_ptr<SfxPoolItem> pProperWhich(pNormalizedItem->Clone());
-            pProperWhich->SetWhich( nNormalizedWhichId );
-            _rScriptSetItem.GetItemSet().Put( *pProperWhich );
+            _rScriptSetItem.GetItemSet().Put( pNormalizedItem->CloneSetWhich(nNormalizedWhichId) );
         }
         else
             _rScriptSetItem.GetItemSet().InvalidateItem( nNormalizedWhichId );
diff --git a/forms/source/richtext/rtattributehandler.cxx b/forms/source/richtext/rtattributehandler.cxx
index 7c2845e9b34f..1f17b32c3396 100644
--- a/forms/source/richtext/rtattributehandler.cxx
+++ b/forms/source/richtext/rtattributehandler.cxx
@@ -291,13 +291,12 @@ namespace frm
     {
         if ( _pAdditionalArg )
         {
-            std::unique_ptr<SfxPoolItem> pCorrectWich(_pAdditionalArg->Clone());
-            pCorrectWich->SetWhich( getWhich() );
+            std::unique_ptr<SfxPoolItem> pCorrectWich(_pAdditionalArg->CloneSetWhich(getWhich()));
 
             if ( m_bScriptDependent )
                 putItemForScript( _rNewAttribs, *pCorrectWich, _nForScriptType );
             else
-                _rNewAttribs.Put( *pCorrectWich );
+                _rNewAttribs.Put( std::move(pCorrectWich) );
         }
         else
             OSL_FAIL( "SlotHandler::executeAttribute: need attributes to do something!" );
@@ -433,9 +432,7 @@ namespace frm
         OSL_ENSURE( dynamic_cast<const SfxBoolItem*>( _pAdditionalArg) !=  nullptr, "BooleanHandler::executeAttribute: invalid argument!" );
         if ( _pAdditionalArg )
         {
-            std::unique_ptr<SfxPoolItem> pCorrectWich(_pAdditionalArg->Clone());
-            pCorrectWich->SetWhich( getWhich() );
-            _rNewAttribs.Put( *pCorrectWich );
+            _rNewAttribs.Put( _pAdditionalArg->CloneSetWhich(getWhich()) );
         }
     }
 
diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx
index 3a2ff084d723..4c9052df0a13 100644
--- a/include/svl/itempool.hxx
+++ b/include/svl/itempool.hxx
@@ -57,6 +57,8 @@ protected:
 class SVL_DLLPUBLIC SfxItemPool
 {
     friend struct SfxItemPool_Impl;
+    friend class SfxItemSet;
+    friend class SfxAllItemSet;
 
     const SfxItemInfo*              pItemInfos;
     std::unique_ptr<SfxItemPool_Impl>               pImpl;
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 88aecf5b6e06..9892855657d1 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -106,6 +106,8 @@ protected:
 
     void                        PutDirect(const SfxPoolItem &rItem);
 
+    virtual const SfxPoolItem*  PutImpl( const SfxPoolItem&, sal_uInt16 nWhich, bool bPassingOwnership );
+
 public:
     struct Pair { sal_uInt16 wid1, wid2; };
 
@@ -191,9 +193,14 @@ public:
 
     // add, delete items, work on items
 public:
-    virtual const SfxPoolItem*  Put( const SfxPoolItem&, sal_uInt16 nWhich );
+    const SfxPoolItem*          Put( const SfxPoolItem& rItem, sal_uInt16 nWhich )
+    { return PutImpl(rItem, nWhich, /*bPassingOwnership*/false); }
+    const SfxPoolItem*          Put( std::unique_ptr<SfxPoolItem> xItem, sal_uInt16 nWhich )
+    { return PutImpl(*xItem.release(), nWhich, /*bPassingOwnership*/true); }
     const SfxPoolItem*          Put( const SfxPoolItem& rItem )
                                 { return Put(rItem, rItem.Which()); }
+    const SfxPoolItem*          Put( std::unique_ptr<SfxPoolItem> xItem )
+                                { auto nWhich = xItem->Which(); return Put(std::move(xItem), nWhich); }
     bool                        Put( const SfxItemSet&,
                                      bool bInvalidAsDefault = true );
     void                        PutExtended( const SfxItemSet&,
@@ -249,8 +256,8 @@ public:
                                 SfxAllItemSet( const SfxAllItemSet & );
 
     virtual std::unique_ptr<SfxItemSet> Clone( bool bItems = true, SfxItemPool *pToPool = nullptr ) const override;
-    virtual const SfxPoolItem*  Put( const SfxPoolItem&, sal_uInt16 nWhich ) override;
-    using SfxItemSet::Put;
+protected:
+    virtual const SfxPoolItem*  PutImpl( const SfxPoolItem&, sal_uInt16 nWhich, bool bPassingOwnership ) override;
 };
 
 #endif // INCLUDED_SVL_ITEMSET_HXX
diff --git a/reportdesign/source/ui/misc/UITools.cxx b/reportdesign/source/ui/misc/UITools.cxx
index 395cb6c32452..220e913b2d09 100644
--- a/reportdesign/source/ui/misc/UITools.cxx
+++ b/reportdesign/source/ui/misc/UITools.cxx
@@ -272,10 +272,9 @@ namespace
                 const SfxPoolItem* pItem = _rItemSet.GetItem(rProp.nWID);
                 if ( pItem )
                 {
-                    ::std::unique_ptr<SfxPoolItem> pClone(pItem->Clone());
+                    ::std::unique_ptr<SfxPoolItem> pClone(pItem->CloneSetWhich(rProp.nWID));
                     pClone->PutValue(_xShape->getPropertyValue(rProp.sName), rProp.nMemberId);
-                    pClone->SetWhich(rProp.nWID);
-                    _rItemSet.Put(*pClone);
+                    _rItemSet.Put(std::move(pClone));
                 }
             }
         }
diff --git a/sc/source/filter/excel/xlroot.cxx b/sc/source/filter/excel/xlroot.cxx
index c1044e216115..977f848061d6 100644
--- a/sc/source/filter/excel/xlroot.cxx
+++ b/sc/source/filter/excel/xlroot.cxx
@@ -388,12 +388,9 @@ ScHeaderEditEngine& XclRoot::GetHFEditEngine() const
         SfxItemSet aItemSet( *GetDoc().GetPool(), svl::Items<ATTR_PATTERN_START, ATTR_PATTERN_END>{} );
         ScPatternAttr::FillToEditItemSet( *pEditSet, aItemSet );
         // FillToEditItemSet() adjusts font height to 1/100th mm, we need twips
-        std::unique_ptr<SfxPoolItem> pNewItem( aItemSet.Get( ATTR_FONT_HEIGHT ).CloneSetWhich(EE_CHAR_FONTHEIGHT));
-        pEditSet->Put( *pNewItem );
-        pNewItem = aItemSet.Get( ATTR_CJK_FONT_HEIGHT ).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK);
-        pEditSet->Put( *pNewItem );
-        pNewItem = aItemSet.Get( ATTR_CTL_FONT_HEIGHT ).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL);
-        pEditSet->Put( *pNewItem );
+        pEditSet->Put( aItemSet.Get( ATTR_FONT_HEIGHT ).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
+        pEditSet->Put( aItemSet.Get( ATTR_CJK_FONT_HEIGHT ).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) );
+        pEditSet->Put( aItemSet.Get( ATTR_CTL_FONT_HEIGHT ).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
         rEE.SetDefaults( pEditSet );    // takes ownership
    }
     return *mrData.mxHFEditEngine;
diff --git a/sc/source/filter/ftools/ftools.cxx b/sc/source/filter/ftools/ftools.cxx
index 8f9eaed44279..c34c446ea482 100644
--- a/sc/source/filter/ftools/ftools.cxx
+++ b/sc/source/filter/ftools/ftools.cxx
@@ -211,8 +211,7 @@ void ScfTools::PutItem( SfxItemSet& rItemSet, const SfxPoolItem& rItem, sal_uInt
 {
     if( !bSkipPoolDef || (rItem != rItemSet.GetPool()->GetDefaultItem( nWhichId )) )
     {
-        std::unique_ptr<SfxPoolItem> pNewItem(rItem.CloneSetWhich(nWhichId));
-        rItemSet.Put( *pNewItem );
+        rItemSet.Put( rItem.CloneSetWhich(nWhichId) );
     }
 }
 
diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index 3f3710326292..f6f27d1b061c 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -271,27 +271,23 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu
                         {
                             if ( pFont )
                             {
-                                std::unique_ptr<SfxPoolItem> pNewItem(pFont->CloneSetWhich(
-                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT )));
-                                pAttrItemSet->Put( *pNewItem );
+                                pAttrItemSet->Put( pFont->CloneSetWhich(
+                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT )) );
                             }
                             if ( pHeight )
                             {
-                                std::unique_ptr<SfxPoolItem> pNewItem(pHeight->CloneSetWhich(
-                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT_HEIGHT )));
-                                pAttrItemSet->Put( *pNewItem );
+                                pAttrItemSet->Put( pHeight->CloneSetWhich(
+                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT_HEIGHT )) );
                             }
                             if ( pWeight )
                             {
-                                std::unique_ptr<SfxPoolItem> pNewItem(pWeight->CloneSetWhich(
-                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT_WEIGHT )));
-                                pAttrItemSet->Put( *pNewItem );
+                                pAttrItemSet->Put( pWeight->CloneSetWhich(
+                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT_WEIGHT )) );
                             }
                             if ( pPosture )
                             {
-                                std::unique_ptr<SfxPoolItem> pNewItem(pPosture->CloneSetWhich(
-                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT_POSTURE )));
-                                pAttrItemSet->Put( *pNewItem );
+                                pAttrItemSet->Put( pPosture->CloneSetWhich(
+                                        ScGlobal::GetScriptedWhichID(nScript, ATTR_FONT_POSTURE )) );
                             }
                         }
                     }
diff --git a/sc/source/ui/Accessibility/AccessibleText.cxx b/sc/source/ui/Accessibility/AccessibleText.cxx
index 0e6d2dfb8320..acacc91ba421 100644
--- a/sc/source/ui/Accessibility/AccessibleText.cxx
+++ b/sc/source/ui/Accessibility/AccessibleText.cxx
@@ -1132,12 +1132,9 @@ SvxTextForwarder* ScAccessibleHeaderTextData::GetTextForwarder()
         rPattern.FillEditItemSet( &aDefaults );
         //  FillEditItemSet adjusts font height to 1/100th mm,
         //  but for header/footer twips is needed, as in the PatternAttr:
-        std::unique_ptr<SfxPoolItem> pNewItem(rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT));
-        aDefaults.Put( *pNewItem );
-        pNewItem = rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK);
-        aDefaults.Put( *pNewItem );
-        pNewItem = rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL);
-        aDefaults.Put( *pNewItem );
+        aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
+        aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) );
+        aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
         aDefaults.Put( SvxAdjustItem( meAdjust, EE_PARA_JUST ) );
         pHdrEngine->SetDefaults( aDefaults );
 
diff --git a/sc/source/ui/pagedlg/tphfedit.cxx b/sc/source/ui/pagedlg/tphfedit.cxx
index 583394658f74..8f647e26e579 100644
--- a/sc/source/ui/pagedlg/tphfedit.cxx
+++ b/sc/source/ui/pagedlg/tphfedit.cxx
@@ -182,12 +182,9 @@ void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
     rPattern.FillEditItemSet( pSet );
     //  FillEditItemSet adjusts font height to 1/100th mm,
     //  but for header/footer twips is needed, as in the PatternAttr:
-    std::unique_ptr<SfxPoolItem> pNewItem(rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT));
-    pSet->Put( *pNewItem );
-    pNewItem = rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK);
-    pSet->Put( *pNewItem );
-    pNewItem = rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL);
-    pSet->Put( *pNewItem );
+    pSet->Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
+    pSet->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) );
+    pSet->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
     if (mbRTL)
         pSet->Put( SvxAdjustItem( SvxAdjust::Right, EE_PARA_JUST ) );
     pEdEngine->SetDefaults( pSet );
diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx
index f034e1a8f915..5fad23d0df1a 100644
--- a/sc/source/ui/unoobj/textuno.cxx
+++ b/sc/source/ui/unoobj/textuno.cxx
@@ -219,12 +219,9 @@ SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder()
         rPattern.FillEditItemSet( &aDefaults );
         //  FillEditItemSet adjusts font height to 1/100th mm,
         //  but for header/footer twips is needed, as in the PatternAttr:
-        std::unique_ptr<SfxPoolItem> pNewItem( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
-        aDefaults.Put( *pNewItem );
-        pNewItem = rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK);
-        aDefaults.Put( *pNewItem );
-        pNewItem = rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL);
-        aDefaults.Put( *pNewItem );
+        aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
+        aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ) ;
+        aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
         pHdrEngine->SetDefaults( aDefaults );
 
         ScHeaderFieldData aData;
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 0f085f50e913..03fb29f44555 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -2210,8 +2210,7 @@ void ScFormatShell::GetAttrState( SfxItemSet& rSet )
             break;
             case SID_ATTR_BRUSH:
             {
-                std::unique_ptr<SfxPoolItem> pNewItem(rBrushItem.CloneSetWhich(GetPool().GetWhich(nWhich)));
-                rSet.Put( *pNewItem );
+                rSet.Put( rBrushItem.CloneSetWhich(GetPool().GetWhich(nWhich)) );
             }
             break;
             case SID_SCATTR_CELLPROTECTION:
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index ca7b8a8e919a..25e9f7e10d73 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -1729,12 +1729,9 @@ void ScPrintFunc::MakeEditEngine()
         rPattern.FillEditItemSet( pEditDefaults.get() );
         //  FillEditItemSet adjusts font height to 1/100th mm,
         //  but for header/footer twips is needed, as in the PatternAttr:
-        std::unique_ptr<SfxPoolItem> pNewItem(rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT));
-        pEditDefaults->Put( *pNewItem );
-        pNewItem = rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK);
-        pEditDefaults->Put( *pNewItem );
-        pNewItem = rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL);
-        pEditDefaults->Put( *pNewItem );
+        pEditDefaults->Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
+        pEditDefaults->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) );
+        pEditDefaults->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
         //  don't use font color, because background color is not used
         //! there's no way to set the background for note pages
         pEditDefaults->ClearItem( EE_CHAR_COLOR );
diff --git a/sc/source/ui/view/viewutil.cxx b/sc/source/ui/view/viewutil.cxx
index 1cfa805b985c..9eb5ea31ee44 100644
--- a/sc/source/ui/view/viewutil.cxx
+++ b/sc/source/ui/view/viewutil.cxx
@@ -64,8 +64,7 @@ void ScViewUtil::PutItemScript( SfxItemSet& rShellSet, const SfxItemSet& rCoreSe
     const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
     if (pI)
     {
-        std::unique_ptr<SfxPoolItem> pNewItem(pI->CloneSetWhich(nWhichId));
-        rShellSet.Put( *pNewItem );
+        rShellSet.Put( pI->CloneSetWhich(nWhichId) );
     }
     else
         rShellSet.InvalidateItem( nWhichId );
diff --git a/sd/source/ui/dlg/dlgolbul.cxx b/sd/source/ui/dlg/dlgolbul.cxx
index 1d71948dcc4d..a019f5da544f 100644
--- a/sd/source/ui/dlg/dlgolbul.cxx
+++ b/sd/source/ui/dlg/dlgolbul.cxx
@@ -96,8 +96,7 @@ OutlineBulletDlg::OutlineBulletDlg(weld::Window* pParent, const SfxItemSet* pAtt
 
         DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in Pool! [CL]" );
 
-        std::unique_ptr<SfxPoolItem> pNewItem(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
-        m_aInputSet.Put(*pNewItem);
+        m_aInputSet.Put(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
     }
 
     if (m_bTitle && m_aInputSet.GetItemState(EE_PARA_NUMBULLET) == SfxItemState::SET )
diff --git a/sd/source/ui/func/fuolbull.cxx b/sd/source/ui/func/fuolbull.cxx
index 72262c7235f7..6680ebfc4761 100644
--- a/sd/source/ui/func/fuolbull.cxx
+++ b/sd/source/ui/func/fuolbull.cxx
@@ -335,8 +335,7 @@ const SfxPoolItem* FuOutlineBullet::GetNumBulletItem(SfxItemSet& aNewAttr, sal_u
 
             //DBG_ASSERT( pItem, "No EE_PARA_NUMBULLET in the Pool!" );
 
-            std::unique_ptr<SfxPoolItem> pNewItem(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
-            aNewAttr.Put(*pNewItem);
+            aNewAttr.Put(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
 
             if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET) == SfxItemState::SET )
             {
diff --git a/sd/source/ui/func/futempl.cxx b/sd/source/ui/func/futempl.cxx
index b30f17008e41..5d918ddbd193 100644
--- a/sd/source/ui/func/futempl.cxx
+++ b/sd/source/ui/func/futempl.cxx
@@ -436,7 +436,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq )
                             std::unique_ptr<SfxPoolItem> pNewItem = static_cast<const XFillBitmapItem*>(pOldItem)->checkForUniqueItem( mpDoc );
                             if( pNewItem )
                             {
-                                rAttr.Put( *pNewItem );
+                                rAttr.Put( std::move(pNewItem) );
                             }
                         }
                         if( rAttr.GetItemState( XATTR_LINEDASH ) == SfxItemState::SET )
@@ -445,7 +445,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq )
                             std::unique_ptr<SfxPoolItem> pNewItem = static_cast<const XLineDashItem*>(pOldItem)->checkForUniqueItem( mpDoc );
                             if( pNewItem )
                             {
-                                rAttr.Put( *pNewItem );
+                                rAttr.Put( std::move(pNewItem) );
                             }
                         }
                         if( rAttr.GetItemState( XATTR_LINESTART ) == SfxItemState::SET )
@@ -454,7 +454,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq )
                             std::unique_ptr<SfxPoolItem> pNewItem = static_cast<const XLineStartItem*>(pOldItem)->checkForUniqueItem( mpDoc );
                             if( pNewItem )
                             {
-                                rAttr.Put( *pNewItem );
+                                rAttr.Put( std::move(pNewItem) );
                             }
                         }
                         if( rAttr.GetItemState( XATTR_LINEEND ) == SfxItemState::SET )
@@ -463,7 +463,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq )
                             std::unique_ptr<SfxPoolItem> pNewItem = static_cast<const XLineEndItem*>(pOldItem)->checkForUniqueItem( mpDoc );
                             if( pNewItem )
                             {
-                                rAttr.Put( *pNewItem );
+                                rAttr.Put( std::move(pNewItem) );
                             }
                         }
                         if( rAttr.GetItemState( XATTR_FILLGRADIENT ) == SfxItemState::SET )
@@ -472,7 +472,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq )
                             std::unique_ptr<SfxPoolItem> pNewItem = static_cast<const XFillGradientItem*>(pOldItem)->checkForUniqueItem( mpDoc );
                             if( pNewItem )
                             {
-                                rAttr.Put( *pNewItem );
+                                rAttr.Put( std::move(pNewItem) );
                             }
                         }
                         if( rAttr.GetItemState( XATTR_FILLFLOATTRANSPARENCE ) == SfxItemState::SET )
@@ -481,7 +481,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq )
                             std::unique_ptr<SfxPoolItem> pNewItem = static_cast<const XFillFloatTransparenceItem*>(pOldItem)->checkForUniqueItem( mpDoc );
                             if( pNewItem )
                             {
-                                rAttr.Put( *pNewItem );
+                                rAttr.Put( std::move(pNewItem) );
                             }
                         }
                         if( rAttr.GetItemState( XATTR_FILLHATCH ) == SfxItemState::SET )
@@ -490,7 +490,7 @@ void FuTemplate::DoExecute( SfxRequest& rReq )
                             std::unique_ptr<SfxPoolItem> pNewItem = static_cast<const XFillHatchItem*>(pOldItem)->checkForUniqueItem( mpDoc );
                             if( pNewItem )
                             {
-                                rAttr.Put( *pNewItem );
+                                rAttr.Put( std::move(pNewItem) );
                             }
                         }
 
diff --git a/sd/source/ui/view/drtxtob.cxx b/sd/source/ui/view/drtxtob.cxx
index a5694b2c5af3..bf4deae1094a 100644
--- a/sd/source/ui/view/drtxtob.cxx
+++ b/sd/source/ui/view/drtxtob.cxx
@@ -224,8 +224,7 @@ void TextObjectBar::GetAttrState( SfxItemSet& rSet )
                     }
                     else
                     {
-                        std::unique_ptr<SfxPoolItem> pNewItem(pI->CloneSetWhich(nWhich));
-                        aAttrSet.Put( *pNewItem );
+                        aAttrSet.Put( pI->CloneSetWhich(nWhich) );
                     }
                 }
                 else
diff --git a/sd/source/ui/view/outlnvsh.cxx b/sd/source/ui/view/outlnvsh.cxx
index 7f6e58798ac3..85ab5688c609 100644
--- a/sd/source/ui/view/outlnvsh.cxx
+++ b/sd/source/ui/view/outlnvsh.cxx
@@ -1268,7 +1268,7 @@ void OutlineViewShell::GetStatusBarState(SfxItemSet& rSet)
         nZoomValues &= ~SvxZoomEnableFlags::PAGEWIDTH;
 
         pZoomItem->SetValueSet( nZoomValues );
-        rSet.Put( *pZoomItem );
+        rSet.Put( std::move(pZoomItem) );
     }
 
     if( SfxItemState::DEFAULT == rSet.GetItemState( SID_ATTR_ZOOMSLIDER ) )
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index 75fcbc469c32..09b321866f2e 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -893,8 +893,7 @@ const SfxPoolItem* ViewShell::GetNumBulletItem(SfxItemSet& aNewAttr, sal_uInt16&
             if( pItem == nullptr )
                 pItem = aNewAttr.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET);
 
-            std::unique_ptr<SfxPoolItem> pNewItem(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
-            aNewAttr.Put(*pNewItem);
+            aNewAttr.Put(pItem->CloneSetWhich(EE_PARA_NUMBULLET));
 
             if(bTitle && aNewAttr.GetItemState(EE_PARA_NUMBULLET) == SfxItemState::SET )
             {
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index c18e0405667f..bed2259d40ea 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -443,10 +443,13 @@ bool SfxItemSet::HasItem(sal_uInt16 nWhich, const SfxPoolItem** ppItem) const
     return bRet;
 }
 
-const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich )
+const SfxPoolItem* SfxItemSet::PutImpl( const SfxPoolItem& rItem, sal_uInt16 nWhich, bool bPassingOwnership )
 {
     if ( !nWhich )
+    {
+        assert(!bPassingOwnership);
         return nullptr; //FIXME: Only because of Outliner bug
+    }
 
     SfxPoolItem const** ppFnd = m_pItems.get();
     const sal_uInt16* pPtr = m_pWhichRanges;
@@ -460,13 +463,16 @@ const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich
             {
                 // Same Item already present?
                 if ( *ppFnd == &rItem )
+                {
+                    assert(!bPassingOwnership);
                     return nullptr;
+                }
 
                 // Will 'dontcare' or 'disabled' be overwritten with some real value?
                 if ( rItem.Which() && ( IsInvalidItem(*ppFnd) || !(*ppFnd)->Which() ) )
                 {
                     auto const old = *ppFnd;
-                    *ppFnd = &m_pPool->Put( rItem, nWhich );
+                    *ppFnd = &m_pPool->PutImpl( rItem, nWhich, bPassingOwnership );
                     if (!IsInvalidItem(old)) {
                         assert(old->Which() == 0);
                         delete old;
@@ -480,16 +486,22 @@ const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich
                     if (IsInvalidItem(*ppFnd) || (*ppFnd)->Which() != 0) {
                         *ppFnd = rItem.Clone(m_pPool);
                     }
+                    if (bPassingOwnership)
+                        delete &rItem;
                     return nullptr;
                 }
                 else
                 {
                     // Same value already present?
                     if ( rItem == **ppFnd )
+                    {
+                        if (bPassingOwnership)
+                            delete &rItem;
                         return nullptr;
+                    }
 
                     // Add the new one, remove the old one
-                    const SfxPoolItem& rNew = m_pPool->Put( rItem, nWhich );
+                    const SfxPoolItem& rNew = m_pPool->PutImpl( rItem, nWhich, bPassingOwnership );
                     const SfxPoolItem* pOld = *ppFnd;
                     *ppFnd = &rNew;
                     if (SfxItemPool::IsWhich(nWhich))
@@ -501,9 +513,14 @@ const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich
             {
                 ++m_nCount;
                 if( !rItem.Which() )
+                {
                     *ppFnd = rItem.Clone(m_pPool);
-                else {
-                    const SfxPoolItem& rNew = m_pPool->Put( rItem, nWhich );
+                    if (bPassingOwnership)
+                        delete &rItem;
+                }
+                else
+                {
+                    const SfxPoolItem& rNew = m_pPool->PutImpl( rItem, nWhich, bPassingOwnership );
                     *ppFnd = &rNew;
                     if (SfxItemPool::IsWhich(nWhich))
                     {
@@ -514,7 +531,7 @@ const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich
                     }
                 }
             }
-            SAL_WARN_IF(m_pPool->IsItemPoolable(nWhich) &&
+            SAL_WARN_IF(!bPassingOwnership && m_pPool->IsItemPoolable(nWhich) &&
                         dynamic_cast<const SfxSetItem*>( &rItem ) == nullptr &&
                         **ppFnd != rItem,
                         "svl.items", "putted Item unequal, with ID/pos " << nWhich );
@@ -523,6 +540,8 @@ const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich
         ppFnd += *(pPtr+1) - *pPtr + 1;
         pPtr += 2;
     }
+    if (bPassingOwnership)
+        delete &rItem;
     return nullptr;
 }
 
@@ -1582,7 +1601,7 @@ static void AddItem_Impl(std::unique_ptr<SfxPoolItem const*[]> & rpItems, sal_uI
 /**
  * Putting with automatic extension of the WhichId with the ID of the Item.
  */
-const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich )
+const SfxPoolItem* SfxAllItemSet::PutImpl( const SfxPoolItem& rItem, sal_uInt16 nWhich, bool bPassingOwnership )
 {
     sal_uInt16 nPos = 0; // Position for 'rItem' in 'm_pItems'
     const sal_uInt16 nItemCount = TotalCount();
@@ -1668,7 +1687,7 @@ const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhi
     }
 
     // Add new Item to Pool
-    const SfxPoolItem& rNew = m_pPool->Put( rItem, nWhich );
+    const SfxPoolItem& rNew = m_pPool->PutImpl( rItem, nWhich, bPassingOwnership );
 
     // Remember old Item
     bool bIncrementCount = false;
diff --git a/svl/source/items/poolcach.cxx b/svl/source/items/poolcach.cxx
index 01f238caa3fb..05401669216c 100644
--- a/svl/source/items/poolcach.cxx
+++ b/svl/source/items/poolcach.cxx
@@ -88,9 +88,7 @@ const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem )
     }
     else
         pNewItem->GetItemSet().Put( *pSetToPut );
-    const SfxSetItem* pNewPoolItem = &pPool->Put( *pNewItem );
-    DBG_ASSERT( pNewPoolItem != pNewItem.get(), "Pool: same in and out?" );
-    pNewItem.reset();
+    const SfxSetItem* pNewPoolItem = &pPool->Put( std::move(pNewItem) );
 
     // Adapt refcount; one each for the cache
     pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 );
diff --git a/svx/source/dialog/hdft.cxx b/svx/source/dialog/hdft.cxx
index 099db34674bc..5f5081c9be39 100644
--- a/svx/source/dialog/hdft.cxx
+++ b/svx/source/dialog/hdft.cxx
@@ -249,7 +249,7 @@ bool SvxHFPage::FillItemSet( SfxItemSet* rSet )
     {
         std::unique_ptr<SfxBoolItem> pBoolItem(static_cast<SfxBoolItem*>(pPool->GetDefaultItem(nWDynSpacing).Clone()));
         pBoolItem->SetValue(m_xDynSpacingCB->get_active());
-        aSet.Put(*pBoolItem);
+        aSet.Put(std::move(pBoolItem));
     }
 
     // Size
diff --git a/svx/source/sdr/properties/itemsettools.cxx b/svx/source/sdr/properties/itemsettools.cxx
index 63b0ca75acda..a47e22dcd091 100644
--- a/svx/source/sdr/properties/itemsettools.cxx
+++ b/svx/source/sdr/properties/itemsettools.cxx
@@ -84,7 +84,7 @@ namespace sdr
                     {
                         std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
                         pNewItem->ScaleMetrics(nMul, nDiv);
-                        rSet.Put(*pNewItem);
+                        rSet.Put(std::move(pNewItem));
                     }
                 }
                 nWhich = aIter.NextWhich();
diff --git a/sw/source/core/doc/DocumentStylePoolManager.cxx b/sw/source/core/doc/DocumentStylePoolManager.cxx
index a7a0a68850f5..8b4c1ba85393 100644
--- a/sw/source/core/doc/DocumentStylePoolManager.cxx
+++ b/sw/source/core/doc/DocumentStylePoolManager.cxx
@@ -1317,9 +1317,9 @@ SwTextFormatColl* DocumentStylePoolManager::GetTextCollFromPool( sal_uInt16 nId,
                 aLR.SetLeft( GetMetricVal( CM_1 ));
                 aLR.SetRight( GetMetricVal( CM_1 ));
                 aSet.Put( aLR );
-                std::shared_ptr<SvxULSpaceItem> aUL(static_cast<SvxULSpaceItem*>(pNewColl->GetULSpace().Clone()));
+                std::unique_ptr<SvxULSpaceItem> aUL(static_cast<SvxULSpaceItem*>(pNewColl->GetULSpace().Clone()));
                 aUL->SetLower( HTML_PARSPACE );
-                aSet.Put(*aUL);
+                aSet.Put(std::move(aUL));
             }
             break;
 
@@ -1332,9 +1332,9 @@ SwTextFormatColl* DocumentStylePoolManager::GetTextCollFromPool( sal_uInt16 nId,
 
                 // The lower paragraph distance is set explicitly (makes
                 // assigning hard attributes easier)
-                std::shared_ptr<SvxULSpaceItem> aULSpaceItem(static_cast<SvxULSpaceItem*>(pNewColl->GetULSpace().Clone()));
+                std::unique_ptr<SvxULSpaceItem> aULSpaceItem(static_cast<SvxULSpaceItem*>(pNewColl->GetULSpace().Clone()));
                 aULSpaceItem->SetLower( 0 );
-                aSet.Put(*aULSpaceItem);
+                aSet.Put(std::move(aULSpaceItem));
             }
             break;
 
@@ -1349,13 +1349,13 @@ SwTextFormatColl* DocumentStylePoolManager::GetTextCollFromPool( sal_uInt16 nId,
                 aSet.Put( SwParaConnectBorderItem( false ) );
                 SetAllScriptItem( aSet, SvxFontHeightItem(120, 100, RES_CHRATR_FONTSIZE) );
 
-                std::shared_ptr<SvxULSpaceItem> aUL;
+                std::unique_ptr<SvxULSpaceItem> aUL;
                 {
                     pNewColl->SetNextTextFormatColl( *GetTextCollFromPool( RES_POOLCOLL_TEXT ));
                     aUL.reset(static_cast<SvxULSpaceItem*>(pNewColl->GetULSpace().Clone()));
                 }
                 aUL->SetLower( HTML_PARSPACE );
-                aSet.Put(*aUL);
+                aSet.Put(std::move(aUL));
                 SwFormatLineNumber aLN;
                 aLN.SetCountLines( false );
                 aSet.Put( aLN );
@@ -1364,22 +1364,22 @@ SwTextFormatColl* DocumentStylePoolManager::GetTextCollFromPool( sal_uInt16 nId,
 
         case RES_POOLCOLL_HTML_DD:
             {
-                std::shared_ptr<SvxLRSpaceItem> aLR(static_cast<SvxLRSpaceItem*>(pNewColl->GetLRSpace().Clone()));
+                std::unique_ptr<SvxLRSpaceItem> aLR(static_cast<SvxLRSpaceItem*>(pNewColl->GetLRSpace().Clone()));
                 // We indent by 1 cm. The IDs are always 2 away from each other!
                 aLR->SetLeft( GetMetricVal( CM_1 ));
-                aSet.Put(*aLR);
+                aSet.Put(std::move(aLR));
             }
             break;
         case RES_POOLCOLL_HTML_DT:
             {
-                std::shared_ptr<SvxLRSpaceItem> aLR;
+                std::unique_ptr<SvxLRSpaceItem> aLR;
                 {
                     pNewColl->SetNextTextFormatColl( *GetTextCollFromPool( RES_POOLCOLL_HTML_DD ));
                     aLR.reset(static_cast<SvxLRSpaceItem*>(pNewColl->GetLRSpace().Clone()));
                 }
                 // We indent by 0 cm. The IDs are always 2 away from each other!
                 aLR->SetLeft( 0 );
-                aSet.Put( *aLR );
+                aSet.Put( std::move(aLR) );
             }
             break;
         }
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index cad5209f32a2..4d8775fa3514 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -785,9 +785,9 @@ lcl_InsertLabel(SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable,
                 pNewSet->Put( pOldFormat->GetAnchor() );
 
                 // The new one should be changeable in its height.
-                std::shared_ptr<SwFormatFrameSize> aFrameSize(static_cast<SwFormatFrameSize*>(pOldFormat->GetFrameSize().Clone()));
+                std::unique_ptr<SwFormatFrameSize> aFrameSize(static_cast<SwFormatFrameSize*>(pOldFormat->GetFrameSize().Clone()));
                 aFrameSize->SetHeightSizeType( ATT_MIN_SIZE );
-                pNewSet->Put( *aFrameSize );
+                pNewSet->Put( std::move(aFrameSize) );
 
                 SwStartNode* pSttNd = rDoc.GetNodes().MakeTextSection(
                             SwNodeIndex( rDoc.GetNodes().GetEndOfAutotext() ),
@@ -849,7 +849,7 @@ lcl_InsertLabel(SwDoc & rDoc, SwTextFormatColls *const pTextFormatCollTable,
                 }
                 aFrameSize->SetWidthPercent(isMath ? 0 : 100);
                 aFrameSize->SetHeightPercent(SwFormatFrameSize::SYNCED);
-                pNewSet->Put( *aFrameSize );
+                pNewSet->Put( std::move(aFrameSize) );
 
                 // Hard-set the attributes, because they could come from the Template
                 // and then size calculations could not be correct anymore.
diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx
index 0db28109528b..2f1f20d89175 100644
--- a/sw/source/core/doc/poolfmt.cxx
+++ b/sw/source/core/doc/poolfmt.cxx
@@ -103,15 +103,9 @@ void SetAllScriptItem( SfxItemSet& rSet, const SfxPoolItem& rItem )
     }
 
     if( nWhCJK )
-    {
-        std::unique_ptr<SfxPoolItem> pNewItem(rItem.CloneSetWhich(nWhCJK));
-        rSet.Put( *pNewItem );
-    }
+        rSet.Put( rItem.CloneSetWhich(nWhCJK) );
     if( nWhCTL )
-    {
-        std::unique_ptr<SfxPoolItem> pNewItem(rItem.CloneSetWhich(nWhCTL));
-        rSet.Put( *pNewItem );
-    }
+        rSet.Put( rItem.CloneSetWhich(nWhCTL) );
 }
 
 /// Return the AutoCollection by its Id. If it doesn't
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 430b32422382..e9331971edc0 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -548,12 +548,9 @@ void SwTableAutoFormat::UpdateToSet(sal_uInt8 nPos, SfxItemSet& rSet,
             }
             else
             {
-                std::unique_ptr<SfxPoolItem> pNewItem(rChg.GetHeight().CloneSetWhich(RES_CHRATR_CJK_FONTSIZE));
-                rSet.Put( *pNewItem);
-                pNewItem = rChg.GetWeight().CloneSetWhich(RES_CHRATR_CJK_WEIGHT);
-                rSet.Put( *pNewItem);
-                pNewItem = rChg.GetPosture().CloneSetWhich(RES_CHRATR_CJK_POSTURE);
-                rSet.Put( *pNewItem);
+                rSet.Put( rChg.GetHeight().CloneSetWhich(RES_CHRATR_CJK_FONTSIZE) );
+                rSet.Put( rChg.GetWeight().CloneSetWhich(RES_CHRATR_CJK_WEIGHT) );
+                rSet.Put( rChg.GetPosture().CloneSetWhich(RES_CHRATR_CJK_POSTURE) );
             }
             // do not insert empty CTL font
             const SvxFontItem& rCTLFont = rChg.GetCTLFont();
@@ -566,12 +563,9 @@ void SwTableAutoFormat::UpdateToSet(sal_uInt8 nPos, SfxItemSet& rSet,
             }
             else
             {
-                std::unique_ptr<SfxPoolItem> pNewItem(rChg.GetHeight().CloneSetWhich(RES_CHRATR_CTL_FONTSIZE));
-                rSet.Put( *pNewItem);
-                pNewItem = rChg.GetWeight().CloneSetWhich(RES_CHRATR_CTL_WEIGHT);
-                rSet.Put( *pNewItem);
-                pNewItem = rChg.GetPosture().CloneSetWhich(RES_CHRATR_CTL_POSTURE);
-                rSet.Put( *pNewItem);
+                rSet.Put( rChg.GetHeight().CloneSetWhich(RES_CHRATR_CTL_FONTSIZE) );
+                rSet.Put( rChg.GetWeight().CloneSetWhich(RES_CHRATR_CTL_WEIGHT) );
+                rSet.Put( rChg.GetPosture().CloneSetWhich(RES_CHRATR_CTL_POSTURE) );
             }
             rSet.Put( rChg.GetUnderline() );
             rSet.Put( rChg.GetOverline() );
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 61749c7d77e9..b86b2f52d9f2 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4187,7 +4187,7 @@ void SwDoc::ClearLineNumAttrs( SwPosition const & rPos )
                     pUndo->AddNode( *pTextNode );
                 std::unique_ptr<SfxStringItem> pNewItem(static_cast<SfxStringItem*>(pFormatItem->Clone()));
                 pNewItem->SetValue(OUString());
-                rSet.Put( *pNewItem );
+                rSet.Put( std::move(pNewItem) );
                 pTextNode->SetAttr( rSet );
             }
         }
diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx
index 7c29f0e7c979..ee51d5b9a219 100644
--- a/sw/source/core/tox/ToxTextGenerator.cxx
+++ b/sw/source/core/tox/ToxTextGenerator.cxx
@@ -291,9 +291,9 @@ ToxTextGenerator::CollectAttributesForTox(const SwTextAttr& hint, SwAttrPool& po
         if (pItem->Which() == RES_CHRATR_ESCAPEMENT ||
             pItem->Which() == RES_CHRATR_POSTURE ||
             pItem->Which() == RES_CHRATR_CJK_POSTURE ||
-            pItem->Which() == RES_CHRATR_CTL_POSTURE) {
-            std::unique_ptr<SfxPoolItem> clonedItem(pItem->Clone());
-            retval->Put(*clonedItem);
+            pItem->Which() == RES_CHRATR_CTL_POSTURE)
+        {
+            retval->Put(std::unique_ptr<SfxPoolItem>(pItem->Clone()));
         }
         if (aIter.IsAtEnd()) {
             break;
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 99358c62f5ab..25e1edcf37d5 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1118,7 +1118,7 @@ bool SwGraphicProperties_Impl::AnyToItemSet(
         {
             std::unique_ptr<SfxPoolItem> pItem(::GetDfltAttr( nIDs[nIndex] )->Clone());
             bRet &= pItem->PutValue(*pAny, nMId );
-            rGrSet.Put(*pItem);
+            rGrSet.Put(std::move(pItem));
         }
     }
 
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 56f991b53364..f73337bbd2f4 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -3004,10 +3004,10 @@ void SwXPageStyle::SetPropertyValues_Impl(const uno::Sequence<OUString>& rProper
             case FN_PARAM_FTN_INFO:
             {
                 const SfxPoolItem& rItem = aBaseImpl.GetItemSet().Get(FN_PARAM_FTN_INFO);
-                const std::unique_ptr<SfxPoolItem> pNewFootnoteItem(rItem.Clone());
+                std::unique_ptr<SfxPoolItem> pNewFootnoteItem(rItem.Clone());
                 if(!pNewFootnoteItem->PutValue(rValues[nProp], pEntry->nMemberId))
                     throw lang::IllegalArgumentException();
-                aBaseImpl.GetItemSet().Put(*pNewFootnoteItem);
+                aBaseImpl.GetItemSet().Put(std::move(pNewFootnoteItem));
                 break;
             }
             default:
diff --git a/sw/source/filter/basflt/fltini.cxx b/sw/source/filter/basflt/fltini.cxx
index 3b6ce6e54469..847930fc84a1 100644
--- a/sw/source/filter/basflt/fltini.cxx
+++ b/sw/source/filter/basflt/fltini.cxx
@@ -404,9 +404,9 @@ void CalculateFlySize(SfxItemSet& rFlySet, const SwNodeIndex& rAnchor,
     }
     else if( MINFLY > static_cast<const SwFormatFrameSize*>(pItem)->GetHeight() )
     {
-        std::shared_ptr<SwFormatFrameSize> aSz(static_cast<SwFormatFrameSize*>(pItem->Clone()));
+        std::unique_ptr<SwFormatFrameSize> aSz(static_cast<SwFormatFrameSize*>(pItem->Clone()));
         aSz->SetHeight( MINFLY );
-        rFlySet.Put( *aSz );
+        rFlySet.Put( std::move(aSz) );
     }
 }
 
diff --git a/sw/source/filter/html/htmldrawreader.cxx b/sw/source/filter/html/htmldrawreader.cxx
index cfaa9ece5011..7dbabfafd73e 100644
--- a/sw/source/filter/html/htmldrawreader.cxx
+++ b/sw/source/filter/html/htmldrawreader.cxx
@@ -238,11 +238,7 @@ static void PutEEPoolItem( SfxItemSet &rEEItemSet,
     }
 
     if( nEEWhich )
-    {
-        std::unique_ptr<SfxPoolItem> pEEItem(rSwItem.Clone());
-        pEEItem->SetWhich( nEEWhich );
-        rEEItemSet.Put( *pEEItem );
-    }
+        rEEItemSet.Put( rSwItem.CloneSetWhich(nEEWhich) );
 }
 
 void SwHTMLParser::NewMarquee( HTMLTable *pCurTable )
diff --git a/sw/source/filter/html/htmldrawwriter.cxx b/sw/source/filter/html/htmldrawwriter.cxx
index 15615ad29698..7666f9f2ca17 100644
--- a/sw/source/filter/html/htmldrawwriter.cxx
+++ b/sw/source/filter/html/htmldrawwriter.cxx
@@ -114,9 +114,7 @@ void SwHTMLWriter::GetEEAttrsFromDrwObj( SfxItemSet& rItemSet,
                 pEEItem = &rObjItemSet.GetPool()->GetDefaultItem(nEEWhich);
 
             // now we clone the item with the which id of the writer
-            std::unique_ptr<SfxPoolItem> pSwItem(pEEItem->Clone());
-            pSwItem->SetWhich( nSwWhich );
-            rItemSet.Put( *pSwItem );
+            rItemSet.Put( pEEItem->CloneSetWhich(nSwWhich) );
         }
 
         nEEWhich = aIter.NextWhich();
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index d08796457530..5ea8e4a5a7db 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -468,8 +468,7 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bWriteCombChars)
     {
         if (const SfxGrabBagItem *pCharFmtGrabBag = aExportSet.GetItem<SfxGrabBagItem>(RES_CHRATR_GRABBAG, false))
         {
-            std::unique_ptr<SfxPoolItem> pNewItem(pCharFmtGrabBag->Clone());
-            SfxGrabBagItem* pNewCharFmtGrabBag = dynamic_cast<SfxGrabBagItem*>(pNewItem.get());
+            std::unique_ptr<SfxGrabBagItem> pNewCharFmtGrabBag(static_cast<SfxGrabBagItem*>(pCharFmtGrabBag->Clone()));
             assert(pNewCharFmtGrabBag);
             auto & rNewFmtMap = pNewCharFmtGrabBag->GetGrabBag();
             for (auto const & item : pAutoFmtGrabBag->GetGrabBag())
@@ -477,7 +476,7 @@ void SwWW8AttrIter::OutAttr( sal_Int32 nSwPos, bool bWriteCombChars)
                 if (item.second.hasValue())
                     rNewFmtMap.erase(item.first);
             }
-            aExportSet.Put(*pNewCharFmtGrabBag);
+            aExportSet.Put(std::move(pNewCharFmtGrabBag));
         }
     }
 
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 551376439e05..f798db5f25cd 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -521,9 +521,7 @@ void SwWW8ImplReader::InsertTxbxStyAttrs( SfxItemSet& rS, sal_uInt16 nColl )
                     ( SfxItemState::SET != rS.GetItemState(nWhich, false) )
                    )
                 {
-                    std::unique_ptr<SfxPoolItem> pCopy(pItem->Clone());
-                    pCopy->SetWhich( nWhich );
-                    rS.Put( *pCopy );
+                    rS.Put( pItem->CloneSetWhich(nWhich) );
                 }
             }
         }
@@ -735,9 +733,7 @@ void SwWW8ImplReader::InsertAttrsAsDrawingAttrs(WW8_CP nStartCp, WW8_CP nEndCp,
                             nWhich != nSlotId
                         )
                         {
-                            std::unique_ptr<SfxPoolItem> pCopy(pItem->Clone());
-                            pCopy->SetWhich( nWhich );
-                            pS->Put( *pCopy );
+                            pS->Put( pItem->CloneSetWhich(nWhich) );
                         }
                     }
                 }
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index bcb276246418..e98fc1b5b4b6 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -3617,7 +3617,7 @@ void SwWW8ImplReader::Read_UnderlineColor(sal_uInt16, const sal_uInt8* pData, sh
                 {
                     std::unique_ptr<SvxUnderlineItem> pUnderline(static_cast<SvxUnderlineItem*>(m_xCurrentItemSet->Get(RES_CHRATR_UNDERLINE, false).Clone()));
                     pUnderline->SetColor( msfilter::util::BGRToRGB(SVBT32ToUInt32(pData)) );
-                    m_xCurrentItemSet->Put( *pUnderline );
+                    m_xCurrentItemSet->Put( std::move(pUnderline) );
                 }
             }
         }
diff --git a/sw/source/filter/xml/xmlitemi.cxx b/sw/source/filter/xml/xmlitemi.cxx
index 68e7ca2f47d7..b14f28bc7534 100644
--- a/sw/source/filter/xml/xmlitemi.cxx
+++ b/sw/source/filter/xml/xmlitemi.cxx
@@ -220,7 +220,7 @@ void SwXMLImportTableItemMapper_Impl::finished(
                         *pNewItem, m_FoMarginValue, Ids[i][1], rUnitConverter);
                 if (bPut)
                 {
-                    rSet.Put(*pNewItem);
+                    rSet.Put(std::move(pNewItem));
                 }
             }
             else
diff --git a/sw/source/ui/chrdlg/numpara.cxx b/sw/source/ui/chrdlg/numpara.cxx
index 65209b1a1658..09a5e3c3f5a9 100644
--- a/sw/source/ui/chrdlg/numpara.cxx
+++ b/sw/source/ui/chrdlg/numpara.cxx
@@ -113,7 +113,7 @@ bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
         {
             std::unique_ptr<SfxUInt16Item> pOutlineLv(static_cast<SfxUInt16Item*>(pOldOutlineLv->Clone()));
             pOutlineLv->SetValue( aOutlineLv );
-            rSet->Put(*pOutlineLv);
+            rSet->Put(std::move(pOutlineLv));
             bModified = true;
         }
     }
@@ -128,7 +128,7 @@ bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
         {
             std::unique_ptr<SfxStringItem> pRule(static_cast<SfxStringItem*>(pOldRule->Clone()));
             pRule->SetValue(aStyle);
-            rSet->Put(*pRule);
+            rSet->Put(std::move(pRule));
             bModified = true;
         }
     }
diff --git a/sw/source/uibase/app/appopt.cxx b/sw/source/uibase/app/appopt.cxx
index 9a0b995679a7..3e9613639f44 100644
--- a/sw/source/uibase/app/appopt.cxx
+++ b/sw/source/uibase/app/appopt.cxx
@@ -133,15 +133,9 @@ std::unique_ptr<SfxItemSet> SwModule::CreateItemSet( sal_uInt16 nId )
             pRet->Put(SwPtrItem(FN_PARAM_PRINTER, pPrt));
         pRet->Put(SwPtrItem(FN_PARAM_WRTSHELL, &rWrtShell));
 
-        std::unique_ptr<SfxPoolItem> pNewItem(
-            rWrtShell.GetDefault(RES_CHRATR_LANGUAGE).CloneSetWhich(SID_ATTR_LANGUAGE) );
-        pRet->Put(*pNewItem);
-
-        pNewItem = rWrtShell.GetDefault(RES_CHRATR_CJK_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CJK_LANGUAGE);
-        pRet->Put(*pNewItem);
-
-        pNewItem = rWrtShell.GetDefault(RES_CHRATR_CTL_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CTL_LANGUAGE);
-        pRet->Put(*pNewItem);
+        pRet->Put(rWrtShell.GetDefault(RES_CHRATR_LANGUAGE).CloneSetWhich(SID_ATTR_LANGUAGE));
+        pRet->Put(rWrtShell.GetDefault(RES_CHRATR_CJK_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CJK_LANGUAGE));
+        pRet->Put(rWrtShell.GetDefault(RES_CHRATR_CTL_LANGUAGE).CloneSetWhich(SID_ATTR_CHAR_CTL_LANGUAGE));
     }
     else
     {
diff --git a/sw/source/uibase/shells/annotsh.cxx b/sw/source/uibase/shells/annotsh.cxx
index b1d0054dec3d..f8bf88323182 100644
--- a/sw/source/uibase/shells/annotsh.cxx
+++ b/sw/source/uibase/shells/annotsh.cxx
@@ -598,8 +598,7 @@ void SwAnnotationShell::Exec( SfxRequest &rReq )
 
     if(nEEWhich && pNewAttrs)
     {
-        std::unique_ptr<SfxPoolItem> pNewItem(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
-        aNewAttr.Put(*pNewItem);
+        aNewAttr.Put(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
     }
 
     tools::Rectangle aOutRect = pOLV->GetOutputArea();
@@ -709,8 +708,7 @@ void SwAnnotationShell::GetState(SfxItemSet& rSet)
                     const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
                     if( pI )
                     {
-                        std::unique_ptr<SfxPoolItem> pNewItem(pI->CloneSetWhich(nWhich));
-                        rSet.Put( *pNewItem );
+                        rSet.Put(pI->CloneSetWhich(nWhich));
                     }
                     else
                         rSet.InvalidateItem( nWhich );
@@ -860,8 +858,7 @@ void SwAnnotationShell::GetState(SfxItemSet& rSet)
 
         if(nEEWhich)
         {
-            std::unique_ptr<SfxPoolItem> pNewItem(aEditAttr.Get(nEEWhich).CloneSetWhich(nWhich));
-            rSet.Put(*pNewItem);
+            rSet.Put(aEditAttr.Get(nEEWhich).CloneSetWhich(nWhich));
             if(nEEWhich == EE_CHAR_KERNING)
             {
                 SfxItemState eState = aEditAttr.GetItemState( EE_CHAR_KERNING );
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index 0a3a735fdd02..96e4c0145703 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -2158,8 +2158,7 @@ void SwBaseShell::GetTextFontCtrlState( SfxItemSet& rSet )
                 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
                 if( pI )
                 {
-                    std::unique_ptr<SfxPoolItem> pNewItem(pI->CloneSetWhich(nWhich));
-                    rSet.Put( *pNewItem );
+                    rSet.Put( pI->CloneSetWhich(nWhich) );
                 }
                 else
                     rSet.InvalidateItem( nWhich );
diff --git a/sw/source/uibase/shells/drwtxtex.cxx b/sw/source/uibase/shells/drwtxtex.cxx
index 6043349c54b9..82950e37743e 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -568,8 +568,7 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
     }
     if(nEEWhich && pNewAttrs)
     {
-        std::unique_ptr<SfxPoolItem> pNewItem(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
-        aNewAttr.Put(*pNewItem);
+        aNewAttr.Put(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
     }
 
     SetAttrToMarked(aNewAttr);
@@ -911,8 +910,7 @@ void SwDrawTextShell::GetDrawTextCtrlState(SfxItemSet& rSet)
                 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
                 if( pI )
                 {
-                    std::unique_ptr<SfxPoolItem> pNewItem(pI->CloneSetWhich(nWhich));
-                    rSet.Put( *pNewItem );
+                    rSet.Put(pI->CloneSetWhich(nWhich));
                 }
                 else
                     rSet.InvalidateItem( nWhich );
@@ -964,8 +962,7 @@ void SwDrawTextShell::GetDrawTextCtrlState(SfxItemSet& rSet)
         }
         if(nEEWhich)
         {
-            std::unique_ptr<SfxPoolItem> pNewItem(aEditAttr.Get(nEEWhich).CloneSetWhich(nWhich));
-            rSet.Put(*pNewItem);
+            rSet.Put(aEditAttr.Get(nEEWhich).CloneSetWhich(nWhich));
         }
 
         nWhich = aIter.NextWhich();
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index ef892924fc27..b9a424e0d2af 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -206,10 +206,7 @@ static SwTableRep*  lcl_TableParamToItemSet( SfxItemSet& rSet, SwWrtShell &rSh )
     //row split
     std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
     if(pSplit)
-    {
-        rSet.Put(*pSplit);
-        pSplit.reset();
-    }
+        rSet.Put(std::move(pSplit));
 
     if(!bTableSel)
     {
@@ -1372,7 +1369,7 @@ void SwTableShell::GetState(SfxItemSet &rSet)
                 {
                     std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
                     if(pSplit)
-                        rSet.Put(*pSplit);
+                        rSet.Put(std::move(pSplit));
                     else
                         rSet.InvalidateItem( nSlot );
                 }
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 8cc0036bf338..657bf72df900 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1589,8 +1589,7 @@ void SwTextShell::GetState( SfxItemSet &rSet )
                 SfxItemSet aSet( GetPool() );
                 rSh.GetCurAttr( aSet );
                 const SvxColorItem& aColorItem = aSet.Get(RES_CHRATR_COLOR);
-                std::unique_ptr<SfxPoolItem> pNewItem(aColorItem.CloneSetWhich(SID_ATTR_CHAR_COLOR2));
-                rSet.Put( *pNewItem );
+                rSet.Put( aColorItem.CloneSetWhich(SID_ATTR_CHAR_COLOR2) );
             }
             break;
         case SID_ATTR_CHAR_COLOR_BACKGROUND:
diff --git a/sw/source/uibase/uiview/formatclipboard.cxx b/sw/source/uibase/uiview/formatclipboard.cxx
index f8f95205dbf6..9fab132e6c1d 100644
--- a/sw/source/uibase/uiview/formatclipboard.cxx
+++ b/sw/source/uibase/uiview/formatclipboard.cxx
@@ -140,7 +140,7 @@ void lcl_getTableAttributes( SfxItemSet& rSet, SwWrtShell &rSh )
 
     std::unique_ptr<SwFormatRowSplit> pSplit = rSh.GetRowSplit();
     if(pSplit)
-        rSet.Put(*pSplit);
+        rSet.Put(std::move(pSplit));
 }
 
 void lcl_setTableAttributes( const SfxItemSet& rSet, SwWrtShell &rSh )
diff --git a/sw/source/uibase/uiview/viewstat.cxx b/sw/source/uibase/uiview/viewstat.cxx
index bc771162bea2..fe6c882e9db7 100644
--- a/sw/source/uibase/uiview/viewstat.cxx
+++ b/sw/source/uibase/uiview/viewstat.cxx
@@ -255,23 +255,19 @@ void SwView::GetState(SfxItemSet &rSet)
             break;
             case SID_ATTR_LANGUAGE:
             {
-                std::unique_ptr<SfxPoolItem> pNewItem(
-                    m_pWrtShell->GetDefault(RES_CHRATR_LANGUAGE).CloneSetWhich(SID_ATTR_LANGUAGE));
-                rSet.Put(*pNewItem);
+                rSet.Put(m_pWrtShell->GetDefault(RES_CHRATR_LANGUAGE).CloneSetWhich(SID_ATTR_LANGUAGE));
             }
             break;
             case RES_CHRATR_CJK_LANGUAGE:
             {
-                std::unique_ptr<SfxPoolItem> pNewItem(
-                    m_pWrtShell->GetDefault(RES_CHRATR_CJK_LANGUAGE).CloneSetWhich(RES_CHRATR_CJK_LANGUAGE));
-                rSet.Put(*pNewItem);
+                rSet.Put(m_pWrtShell->GetDefault(RES_CHRATR_CJK_LANGUAGE)
+                            .CloneSetWhich(RES_CHRATR_CJK_LANGUAGE));
             }
             break;
             case RES_CHRATR_CTL_LANGUAGE:
             {
-                std::unique_ptr<SfxPoolItem> pNewItem(
-                    m_pWrtShell->GetDefault(RES_CHRATR_CTL_LANGUAGE).CloneSetWhich(RES_CHRATR_CTL_LANGUAGE));
-                rSet.Put(*pNewItem);
+                rSet.Put(m_pWrtShell->GetDefault(RES_CHRATR_CTL_LANGUAGE)
+                            .CloneSetWhich(RES_CHRATR_CTL_LANGUAGE));
             }
             break;
             case FN_REDLINE_ON:
@@ -479,8 +475,7 @@ void SwView::GetState(SfxItemSet &rSet)
                 {
                     if (!(m_nSelectionType & SelectionType::DrawObject))
                     {
-                        std::unique_ptr<SfxPoolItem> pNewItem(pState->CloneSetWhich(nWhich));
-                        rSet.Put(*pNewItem);
+                        rSet.Put(pState->CloneSetWhich(nWhich));
                     }
                 }
                 else
diff --git a/sw/source/uibase/utlui/uitool.cxx b/sw/source/uibase/utlui/uitool.cxx
index c44434b25961..17e1a92eac34 100644
--- a/sw/source/uibase/utlui/uitool.cxx
+++ b/sw/source/uibase/utlui/uitool.cxx
@@ -149,7 +149,7 @@ void ConvertAttrCharToGen(SfxItemSet& rSet)
     else
         pGrabBag.reset(new SfxGrabBagItem(RES_CHRATR_GRABBAG));
     pGrabBag->GetGrabBag()["DialogUseCharAttr"] <<= true;
-    rSet.Put(*pGrabBag);
+    rSet.Put(std::move(pGrabBag));
 }
 
 void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet)
commit 38a684f72988f29e1c07bf9fa5a83e275e80e24c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue May 7 12:14:26 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu May 9 08:47:41 2019 +0200

    move constructor for SfxItemSet
    
    Change-Id: If7f51a657606da8aea4bcf01f13468c6ac2086a8
    Reviewed-on: https://gerrit.libreoffice.org/71901
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 0c3acdf549dd..88aecf5b6e06 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -110,6 +110,7 @@ public:
     struct Pair { sal_uInt16 wid1, wid2; };
 
                                 SfxItemSet( const SfxItemSet& );
+                                SfxItemSet( SfxItemSet&& );
 
                                 SfxItemSet( SfxItemPool&);
     template<sal_uInt16... WIDs> SfxItemSet(
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 254e8291b231..c18e0405667f 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -222,31 +222,47 @@ SfxItemSet::SfxItemSet( const SfxItemSet& rASet )
     memcpy( m_pWhichRanges, rASet.m_pWhichRanges, sizeof( sal_uInt16 ) * cnt);
 }
 
+SfxItemSet::SfxItemSet( SfxItemSet&& rASet )
+    : m_pPool( rASet.m_pPool )
+    , m_pParent( rASet.m_pParent )
+    , m_pItems( std::move(rASet.m_pItems) )
+    , m_pWhichRanges( rASet.m_pWhichRanges )
+    , m_nCount( rASet.m_nCount )
+{
+    rASet.m_pPool = nullptr;
+    rASet.m_pParent = nullptr;
+    rASet.m_pWhichRanges = nullptr;
+    rASet.m_nCount = 0;
+}
+
 SfxItemSet::~SfxItemSet()
 {
-    sal_uInt16 nCount = TotalCount();
-    if( Count() )
+    if (m_pWhichRanges) // might be nullptr if we have been moved-from
     {
-        SfxPoolItem const** ppFnd = m_pItems.get();
-        for( sal_uInt16 nCnt = nCount; nCnt; --nCnt, ++ppFnd )
-            if( *ppFnd && !IsInvalidItem(*ppFnd) )
-            {
-                if( !(*ppFnd)->Which() )
-                    delete *ppFnd;
-                else {
-                    // Still multiple references present, so just alter the RefCount
-                    if ( 1 < (*ppFnd)->GetRefCount() && !IsDefaultItem(*ppFnd) )
-                        (*ppFnd)->ReleaseRef();
-                    else
-                        if ( !IsDefaultItem(*ppFnd) )
-                            // Delete from Pool
-                            m_pPool->Remove( **ppFnd );
+        sal_uInt16 nCount = TotalCount();
+        if( Count() )
+        {
+            SfxPoolItem const** ppFnd = m_pItems.get();
+            for( sal_uInt16 nCnt = nCount; nCnt; --nCnt, ++ppFnd )
+                if( *ppFnd && !IsInvalidItem(*ppFnd) )
+                {
+                    if( !(*ppFnd)->Which() )
+                        delete *ppFnd;
+                    else {
+                        // Still multiple references present, so just alter the RefCount
+                        if ( 1 < (*ppFnd)->GetRefCount() && !IsDefaultItem(*ppFnd) )
+                            (*ppFnd)->ReleaseRef();
+                        else
+                            if ( !IsDefaultItem(*ppFnd) )
+                                // Delete from Pool
+                                m_pPool->Remove( **ppFnd );
+                    }
                 }
-            }
+        }
     }
 
     m_pItems.reset();
-    if (m_pWhichRanges != m_pPool->GetFrozenIdRanges())
+    if (m_pPool && m_pWhichRanges != m_pPool->GetFrozenIdRanges())
         delete[] m_pWhichRanges;
     m_pWhichRanges = nullptr; // for invariant-testing
 }


More information about the Libreoffice-commits mailing list