diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-31 09:19:20 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-31 15:50:04 +0200 |
commit | 5b8729a741bd65c2f61ae9caba7ea15a139835e5 (patch) | |
tree | c8e11588f87115b51b932af5b89bd0c68787e0a6 /editeng/source | |
parent | 68a6c70f25762374f7aed0d4d755345c6f37c78d (diff) |
no need to allocate SvxNumRule separately in SvxNumBulletItem
Change-Id: I7903565a468fc0fbec603c88b92cca6560a86728
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116424
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng/source')
-rw-r--r-- | editeng/source/accessibility/AccessibleEditableTextPara.cxx | 2 | ||||
-rw-r--r-- | editeng/source/editeng/editdbg.cxx | 2 | ||||
-rw-r--r-- | editeng/source/items/numitem.cxx | 66 | ||||
-rw-r--r-- | editeng/source/outliner/outliner.cxx | 4 | ||||
-rw-r--r-- | editeng/source/outliner/outlvw.cxx | 14 | ||||
-rw-r--r-- | editeng/source/uno/unonrule.cxx | 15 |
6 files changed, 63 insertions, 40 deletions
diff --git a/editeng/source/accessibility/AccessibleEditableTextPara.cxx b/editeng/source/accessibility/AccessibleEditableTextPara.cxx index fa7c00b85a99..624227a5f64e 100644 --- a/editeng/source/accessibility/AccessibleEditableTextPara.cxx +++ b/editeng/source/accessibility/AccessibleEditableTextPara.cxx @@ -1528,7 +1528,7 @@ namespace accessibility if (rRes.Name == "NumberingLevel") { const SvxNumBulletItem& rNumBullet = rCacheTF.GetParaAttribs(GetParagraphIndex()).Get(EE_PARA_NUMBULLET); - if(rNumBullet.GetNumRule()->GetLevelCount()==0) + if(rNumBullet.GetNumRule().GetLevelCount()==0) { rRes.Value <<= sal_Int16(-1); rRes.Handle = -1; diff --git a/editeng/source/editeng/editdbg.cxx b/editeng/source/editeng/editdbg.cxx index 18b5747bb5bf..d2a97cdb0efa 100644 --- a/editeng/source/editeng/editdbg.cxx +++ b/editeng/source/editeng/editdbg.cxx @@ -83,7 +83,7 @@ static OString DbgOutItem(const SfxItemPool& rPool, const SfxPoolItem& rItem) aDebStr.append("Level"); aDebStr.append(static_cast<sal_Int32>(nLevel)); aDebStr.append('='); - const SvxNumberFormat* pFmt = static_cast<const SvxNumBulletItem&>(rItem).GetNumRule()->Get( nLevel ); + const SvxNumberFormat* pFmt = static_cast<const SvxNumBulletItem&>(rItem).GetNumRule().Get( nLevel ); if ( pFmt ) { aDebStr.append('('); diff --git a/editeng/source/items/numitem.cxx b/editeng/source/items/numitem.cxx index 66e7824d278a..ba935384eb31 100644 --- a/editeng/source/items/numitem.cxx +++ b/editeng/source/items/numitem.cxx @@ -638,6 +638,21 @@ SvxNumRule::SvxNumRule(const SvxNumRule& rCopy) } } +SvxNumRule::SvxNumRule(SvxNumRule&& rCopy) +{ + ++nRefCount; + nLevelCount = rCopy.nLevelCount ; + nFeatureFlags = rCopy.nFeatureFlags ; + bContinuousNumbering = rCopy.bContinuousNumbering; + eNumberingType = rCopy.eNumberingType; + for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++) + { + if(rCopy.aFmts[i]) + aFmts[i] = std::move(rCopy.aFmts[i]); + aFmtsSet[i] = rCopy.aFmtsSet[i]; + } +} + SvxNumRule::SvxNumRule( SvStream &rStream ) : nLevelCount(0) { @@ -759,6 +774,24 @@ SvxNumRule& SvxNumRule::operator=( const SvxNumRule& rCopy ) return *this; } +SvxNumRule& SvxNumRule::operator=( SvxNumRule&& rCopy ) +{ + if (this != &rCopy) + { + nLevelCount = rCopy.nLevelCount; + nFeatureFlags = rCopy.nFeatureFlags; + bContinuousNumbering = rCopy.bContinuousNumbering; + eNumberingType = rCopy.eNumberingType; + for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++) + { + if(rCopy.aFmts[i]) + aFmts[i] = std::move(rCopy.aFmts[i]); + aFmtsSet[i] = rCopy.aFmtsSet[i]; + } + } + return *this; +} + bool SvxNumRule::operator==( const SvxNumRule& rCopy) const { if(nLevelCount != rCopy.nLevelCount || @@ -927,19 +960,19 @@ void SvxNumRule::UnLinkGraphics() SvxNumBulletItem::SvxNumBulletItem(SvxNumRule const & rRule) : SfxPoolItem(SID_ATTR_NUMBERING_RULE), - pNumRule(new SvxNumRule(rRule)) + maNumRule(rRule) { } SvxNumBulletItem::SvxNumBulletItem(SvxNumRule const & rRule, sal_uInt16 _nWhich ) : SfxPoolItem(_nWhich), - pNumRule(new SvxNumRule(rRule)) + maNumRule(rRule) { } SvxNumBulletItem::SvxNumBulletItem(const SvxNumBulletItem& rCopy) : SfxPoolItem(rCopy), - pNumRule(new SvxNumRule(*rCopy.pNumRule)) + maNumRule(rCopy.maNumRule) { } @@ -950,7 +983,7 @@ SvxNumBulletItem::~SvxNumBulletItem() bool SvxNumBulletItem::operator==( const SfxPoolItem& rCopy) const { return SfxPoolItem::operator==(rCopy) && - *pNumRule == *static_cast<const SvxNumBulletItem&>(rCopy).pNumRule; + maNumRule == static_cast<const SvxNumBulletItem&>(rCopy).maNumRule; } SvxNumBulletItem* SvxNumBulletItem::Clone( SfxItemPool * ) const @@ -960,7 +993,7 @@ SvxNumBulletItem* SvxNumBulletItem::Clone( SfxItemPool * ) const bool SvxNumBulletItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const { - rVal <<= SvxCreateNumRule( pNumRule.get() ); + rVal <<= SvxCreateNumRule( maNumRule ); return true; } @@ -971,14 +1004,13 @@ bool SvxNumBulletItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberI { try { - std::unique_ptr<SvxNumRule> pNewRule(new SvxNumRule( SvxGetNumRule( xRule ) )); - if( pNewRule->GetLevelCount() != pNumRule->GetLevelCount() || - pNewRule->GetNumRuleType() != pNumRule->GetNumRuleType() ) + SvxNumRule aNewRule( SvxGetNumRule( xRule ) ); + if( aNewRule.GetLevelCount() != maNumRule.GetLevelCount() || + aNewRule.GetNumRuleType() != maNumRule.GetNumRuleType() ) { - std::unique_ptr<SvxNumRule> pConverted = SvxConvertNumRule( pNewRule.get(), pNumRule->GetLevelCount(), pNumRule->GetNumRuleType() ); - pNewRule = std::move(pConverted); + aNewRule = SvxConvertNumRule( aNewRule, maNumRule.GetLevelCount(), maNumRule.GetNumRuleType() ); } - pNumRule = std::move( pNewRule ); + maNumRule = std::move( aNewRule ); return true; } catch(const lang::IllegalArgumentException&) @@ -992,19 +1024,19 @@ void SvxNumBulletItem::dumpAsXml(xmlTextWriterPtr pWriter) const { (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxNumBulletItem")); (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr())); - pNumRule->dumpAsXml(pWriter); + maNumRule.dumpAsXml(pWriter); (void)xmlTextWriterEndElement(pWriter); } -std::unique_ptr<SvxNumRule> SvxConvertNumRule( const SvxNumRule* pRule, sal_uInt16 nLevels, SvxNumRuleType eType ) +SvxNumRule SvxConvertNumRule( const SvxNumRule& rRule, sal_uInt16 nLevels, SvxNumRuleType eType ) { - const sal_uInt16 nSrcLevels = pRule->GetLevelCount(); - std::unique_ptr<SvxNumRule> pNewRule(new SvxNumRule( pRule->GetFeatureFlags(), nLevels, pRule->IsContinuousNumbering(), eType )); + const sal_uInt16 nSrcLevels = rRule.GetLevelCount(); + SvxNumRule aNewRule(rRule.GetFeatureFlags(), nLevels, rRule.IsContinuousNumbering(), eType ); for( sal_uInt16 nLevel = 0; (nLevel < nLevels) && (nLevel < nSrcLevels); nLevel++ ) - pNewRule->SetLevel( nLevel, pRule->GetLevel( nLevel ) ); + aNewRule.SetLevel( nLevel, rRule.GetLevel( nLevel ) ); - return pNewRule; + return aNewRule; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index 8c74fe883345..9c474131352c 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -1389,8 +1389,8 @@ const SvxNumberFormat* Outliner::GetNumberFormat( sal_Int32 nPara ) const if( nDepth >= 0 ) { const SvxNumBulletItem& rNumBullet = pEditEngine->GetParaAttrib( nPara, EE_PARA_NUMBULLET ); - if ( rNumBullet.GetNumRule()->GetLevelCount() > nDepth ) - pFmt = rNumBullet.GetNumRule()->Get( nDepth ); + if ( rNumBullet.GetNumRule().GetLevelCount() > nDepth ) + pFmt = rNumBullet.GetNumRule().Get( nDepth ); } return pFmt; diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx index da1b2f6d51ec..aabe51c9efd8 100644 --- a/editeng/source/outliner/outlvw.cxx +++ b/editeng/source/outliner/outlvw.cxx @@ -851,7 +851,7 @@ void OutlinerView::ToggleBullets() const SfxItemSet aTmpSet(pOwner->pEditEngine->GetAttribs(aSelection)); const SfxPoolItem& rPoolItem = aTmpSet.GetPool()->GetDefaultItem( EE_PARA_NUMBULLET ); const SvxNumBulletItem* pNumBulletItem = dynamic_cast< const SvxNumBulletItem* >(&rPoolItem); - pDefaultBulletNumRule = pNumBulletItem ? pNumBulletItem->GetNumRule() : nullptr; + pDefaultBulletNumRule = pNumBulletItem ? &pNumBulletItem->GetNumRule() : nullptr; } } @@ -1034,17 +1034,17 @@ void OutlinerView::ApplyBulletsNumbering( const SvxNumBulletItem* pNumBulletItem = dynamic_cast< const SvxNumBulletItem* >(pPoolItem); if (pNumBulletItem) { - const sal_uInt16 nLevelCnt = std::min(pNumBulletItem->GetNumRule()->GetLevelCount(), aNewRule.GetLevelCount()); + const sal_uInt16 nLevelCnt = std::min(pNumBulletItem->GetNumRule().GetLevelCount(), aNewRule.GetLevelCount()); for ( sal_uInt16 nLevel = 0; nLevel < nLevelCnt; ++nLevel ) { - const SvxNumberFormat* pOldFmt = pNumBulletItem->GetNumRule()->Get(nLevel); + const SvxNumberFormat* pOldFmt = pNumBulletItem->GetNumRule().Get(nLevel); const SvxNumberFormat* pNewFmt = aNewRule.Get(nLevel); if (pOldFmt && pNewFmt && (pOldFmt->GetFirstLineOffset() != pNewFmt->GetFirstLineOffset() || pOldFmt->GetAbsLSpace() != pNewFmt->GetAbsLSpace())) { - std::unique_ptr<SvxNumberFormat> pNewFmtClone(new SvxNumberFormat(*pNewFmt)); - pNewFmtClone->SetFirstLineOffset(pOldFmt->GetFirstLineOffset()); - pNewFmtClone->SetAbsLSpace(pOldFmt->GetAbsLSpace()); - aNewRule.SetLevel(nLevel, pNewFmtClone.get()); + SvxNumberFormat aNewFmtClone(*pNewFmt); + aNewFmtClone.SetFirstLineOffset(pOldFmt->GetFirstLineOffset()); + aNewFmtClone.SetAbsLSpace(pOldFmt->GetAbsLSpace()); + aNewRule.SetLevel(nLevel, &aNewFmtClone); } } } diff --git a/editeng/source/uno/unonrule.cxx b/editeng/source/uno/unonrule.cxx index 5180f9d60fdf..9f861b7f9c2a 100644 --- a/editeng/source/uno/unonrule.cxx +++ b/editeng/source/uno/unonrule.cxx @@ -481,18 +481,9 @@ const SvxNumRule& SvxGetNumRule( Reference< XIndexReplace > const & xRule ) return pRule->getNumRule(); } -css::uno::Reference< css::container::XIndexReplace > SvxCreateNumRule(const SvxNumRule* pRule) +css::uno::Reference< css::container::XIndexReplace > SvxCreateNumRule(const SvxNumRule& rRule) { - DBG_ASSERT( pRule, "No default SvxNumRule!" ); - if( pRule ) - { - return new SvxUnoNumberingRules( *pRule ); - } - else - { - SvxNumRule aDefaultRule( SvxNumRuleFlags::BULLET_REL_SIZE | SvxNumRuleFlags::BULLET_COLOR, SVX_MAX_NUM, false); - return new SvxUnoNumberingRules( aDefaultRule ); - } + return new SvxUnoNumberingRules( rRule ); } namespace { @@ -554,7 +545,7 @@ Reference< XAnyCompare > SvxCreateNumRuleCompare() noexcept css::uno::Reference< css::container::XIndexReplace > SvxCreateNumRule() { SvxNumRule aTempRule( SvxNumRuleFlags::NONE, 10, false ); - return SvxCreateNumRule( &aTempRule ); + return SvxCreateNumRule( aTempRule ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |