Kaydet (Commit) e0382c3a authored tarafından Noel Grandin's avatar Noel Grandin

avoid copying when placing items into SfxItemSet

Change-Id: I05c627f590e7794c1ba11b66021dc30aa3285eb0
Reviewed-on: https://gerrit.libreoffice.org/71941
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 38a684f7
......@@ -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);
}
......
......@@ -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 )
......
......@@ -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
{
......
......@@ -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;
}
......
......@@ -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)
{
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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) );
}
}
}
......
......@@ -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;
}
}
......
......@@ -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 );
......
......@@ -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()) );
}
}
......
......@@ -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;
......
......@@ -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
......
......@@ -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));
}
}
}
......
......@@ -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;
......
......@@ -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) );
}
}
......
......@@ -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 )) );
}
}
}
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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:
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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 )
......
......@@ -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 )
{
......
......@@ -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) );
}
}
......
......@@ -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
......
......@@ -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 ) )
......
......@@ -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 )
{
......
......@@ -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;
......
......@@ -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 );
......
......@@ -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
......
......@@ -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();
......
......@@ -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));