sw/source/filter/ascii/parasc.cxx | 46 ++++++++++----------- sw/source/filter/html/htmlatr.cxx | 82 +++++++++++++++++++------------------- sw/source/filter/html/wrthtml.hxx | 3 - sw/source/filter/xml/xmlfmt.cxx | 34 +++++++-------- 4 files changed, 83 insertions(+), 82 deletions(-)
New commits: commit 8dda0309871b371e056c0c0f308203e2a8a0306f Author: Noel Grandin <noelgran...@gmail.com> AuthorDate: Tue Sep 21 20:33:22 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Sep 22 09:07:44 2021 +0200 no need to allocate these SfxItemSet on the heap Change-Id: I21b34386d3f2f408da329b0e5888566cbb126d0e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122402 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/filter/ascii/parasc.cxx b/sw/source/filter/ascii/parasc.cxx index 23bc58230f62..e57a03557637 100644 --- a/sw/source/filter/ascii/parasc.cxx +++ b/sw/source/filter/ascii/parasc.cxx @@ -56,7 +56,7 @@ class SwASCIIParser std::unique_ptr<char[]> m_pArr; const SwAsciiOptions& m_rOpt; SwAsciiOptions m_usedAsciiOptions; - std::unique_ptr<SfxItemSet> m_pItemSet; + std::optional<SfxItemSet> m_oItemSet; tools::Long m_nFileSize; SvtScriptType m_nScript; bool m_bNewDoc; @@ -115,7 +115,7 @@ SwASCIIParser::SwASCIIParser(SwDoc& rD, const SwPaM& rCursor, SvStream& rIn, boo m_pPam.reset(new SwPaM(*rCursor.GetPoint())); m_pArr.reset(new char[ASC_BUFFLEN + 2]); - m_pItemSet = std::make_unique<SfxItemSet>( + m_oItemSet.emplace( m_rDoc.GetAttrPool(), svl::Items<RES_CHRATR_FONT, RES_CHRATR_LANGUAGE, RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_LANGUAGE>); @@ -124,11 +124,11 @@ SwASCIIParser::SwASCIIParser(SwDoc& rD, const SwPaM& rCursor, SvStream& rIn, boo if (m_rOpt.GetLanguage()) { SvxLanguageItem aLang(m_rOpt.GetLanguage(), RES_CHRATR_LANGUAGE); - m_pItemSet->Put(aLang); + m_oItemSet->Put(aLang); aLang.SetWhich(RES_CHRATR_CJK_LANGUAGE); - m_pItemSet->Put(aLang); + m_oItemSet->Put(aLang); aLang.SetWhich(RES_CHRATR_CTL_LANGUAGE); - m_pItemSet->Put(aLang); + m_oItemSet->Put(aLang); } if (m_rOpt.GetFontName().isEmpty()) return; @@ -138,11 +138,11 @@ SwASCIIParser::SwASCIIParser(SwDoc& rD, const SwPaM& rCursor, SvStream& rIn, boo aTextFont = m_rDoc.getIDocumentDeviceAccess().getPrinter(false)->GetFontMetric(aTextFont); SvxFontItem aFont( aTextFont.GetFamilyType(), aTextFont.GetFamilyName(), OUString(), aTextFont.GetPitch(), aTextFont.GetCharSet(), RES_CHRATR_FONT ); - m_pItemSet->Put(aFont); + m_oItemSet->Put(aFont); aFont.SetWhich(RES_CHRATR_CJK_FONT); - m_pItemSet->Put(aFont); + m_oItemSet->Put(aFont); aFont.SetWhich(RES_CHRATR_CTL_FONT); - m_pItemSet->Put(aFont); + m_oItemSet->Put(aFont); } // Calling the parser @@ -179,25 +179,25 @@ ErrCode SwASCIIParser::CallParser() ErrCode nError = ReadChars(); - if (m_pItemSet) + if (m_oItemSet) { // set only the attribute, for scanned scripts. if (!(SvtScriptType::LATIN & m_nScript)) { - m_pItemSet->ClearItem(RES_CHRATR_FONT); - m_pItemSet->ClearItem(RES_CHRATR_LANGUAGE); + m_oItemSet->ClearItem(RES_CHRATR_FONT); + m_oItemSet->ClearItem(RES_CHRATR_LANGUAGE); } if (!(SvtScriptType::ASIAN & m_nScript)) { - m_pItemSet->ClearItem(RES_CHRATR_CJK_FONT); - m_pItemSet->ClearItem(RES_CHRATR_CJK_LANGUAGE); + m_oItemSet->ClearItem(RES_CHRATR_CJK_FONT); + m_oItemSet->ClearItem(RES_CHRATR_CJK_LANGUAGE); } if (!(SvtScriptType::COMPLEX & m_nScript)) { - m_pItemSet->ClearItem(RES_CHRATR_CTL_FONT); - m_pItemSet->ClearItem(RES_CHRATR_CTL_LANGUAGE); + m_oItemSet->ClearItem(RES_CHRATR_CTL_FONT); + m_oItemSet->ClearItem(RES_CHRATR_CTL_LANGUAGE); } - if (m_pItemSet->Count()) + if (m_oItemSet->Count()) { if (m_bNewDoc) { @@ -224,16 +224,16 @@ ErrCode SwASCIIParser::CallParser() { const SfxPoolItem *pItem; if (SfxItemState::SET - == m_pItemSet->GetItemState(*pWhichIds, false, &pItem)) + == m_oItemSet->GetItemState(*pWhichIds, false, &pItem)) { pColl->SetFormatAttr( *pItem ); - m_pItemSet->ClearItem(*pWhichIds); + m_oItemSet->ClearItem(*pWhichIds); } ++pWhichIds; } } - if (m_pItemSet->Count()) - m_rDoc.SetDefault(*m_pItemSet); + if (m_oItemSet->Count()) + m_rDoc.SetDefault(*m_oItemSet); } else if( pInsPam ) { @@ -245,10 +245,10 @@ ErrCode SwASCIIParser::CallParser() // !!!!! OSL_ENSURE( false, "Have to change - hard attr. to para. style" ); - m_rDoc.getIDocumentContentOperations().InsertItemSet(*pInsPam, *m_pItemSet); + m_rDoc.getIDocumentContentOperations().InsertItemSet(*pInsPam, *m_oItemSet); } } - m_pItemSet.reset(); + m_oItemSet.reset(); } pInsPam.reset(); @@ -513,7 +513,7 @@ void SwASCIIParser::InsertText( const OUString& rStr ) { m_rDoc.getIDocumentContentOperations().InsertString(*m_pPam, rStr); - if (m_pItemSet && g_pBreakIt + if (m_oItemSet && g_pBreakIt && m_nScript != (SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX)) m_nScript |= g_pBreakIt->GetAllScriptsOfText(rStr); } diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 43edfe64ce0b..2c9e54a49d62 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -201,7 +201,7 @@ namespace { struct SwHTMLTextCollOutputInfo { OString aToken; // End token to be output - std::unique_ptr<SfxItemSet> pItemSet; // hard attribute + std::optional<SfxItemSet> moItemSet; // hard attribute bool bInNumberBulletList; // in an enumerated list; bool bParaPossible; // a </P> may be output additionally @@ -291,22 +291,22 @@ SwHTMLFormatInfo::SwHTMLFormatInfo( const SwFormat *pF, SwDoc *pDoc, SwDoc *pTem if( pReferenceFormat || nDeep==0 ) { - pItemSet.reset( new SfxItemSet( *pFormat->GetAttrSet().GetPool(), - pFormat->GetAttrSet().GetRanges() ) ); + moItemSet.emplace( *pFormat->GetAttrSet().GetPool(), + pFormat->GetAttrSet().GetRanges() ); // if the differences to a different style are supposed to be // written, hard attribute is necessary. This is always true // for styles that are not derived from HTML-tag styles. - pItemSet->Set( pFormat->GetAttrSet() ); + moItemSet->Set( pFormat->GetAttrSet() ); if( pReferenceFormat ) - SwHTMLWriter::SubtractItemSet( *pItemSet, pReferenceFormat->GetAttrSet(), true ); + SwHTMLWriter::SubtractItemSet( *moItemSet, pReferenceFormat->GetAttrSet(), true ); // delete ItemSet that is empty straight away. This will save work // later on - if( !pItemSet->Count() ) + if( !moItemSet->Count() ) { - pItemSet.reset(); + moItemSet.reset(); } } @@ -355,10 +355,10 @@ SwHTMLFormatInfo::SwHTMLFormatInfo( const SwFormat *pF, SwDoc *pDoc, SwDoc *pTem const SfxPoolItem& rSet = pFormat->GetFormatAttr( aWhichIds[nSet][i] ); if( rSet != rRef ) { - if( !pItemSet ) - pItemSet.reset( new SfxItemSet( *pFormat->GetAttrSet().GetPool(), - pFormat->GetAttrSet().GetRanges() ) ); - pItemSet->Put( rSet ); + if( !moItemSet ) + moItemSet.emplace( *pFormat->GetAttrSet().GetPool(), + pFormat->GetAttrSet().GetRanges() ); + moItemSet->Put( rSet ); } } } @@ -385,10 +385,10 @@ SwHTMLFormatInfo::SwHTMLFormatInfo( const SwFormat *pF, SwDoc *pDoc, SwDoc *pTem LanguageType eLang = rLang.GetLanguage(); if( eLang != eDfltLang ) { - if( !pItemSet ) - pItemSet.reset( new SfxItemSet( *pFormat->GetAttrSet().GetPool(), - pFormat->GetAttrSet().GetRanges() ) ); - pItemSet->Put( rLang ); + if( !moItemSet ) + moItemSet.emplace( *pFormat->GetAttrSet().GetPool(), + pFormat->GetAttrSet().GetRanges() ); + moItemSet->Put( rLang ); } static const sal_uInt16 aWhichIds[3] = @@ -402,10 +402,10 @@ SwHTMLFormatInfo::SwHTMLFormatInfo( const SwFormat *pF, SwDoc *pDoc, SwDoc *pTem static_cast<const SvxLanguageItem&>(pFormat->GetFormatAttr(i)); if( rTmpLang.GetLanguage() != eLang ) { - if( !pItemSet ) - pItemSet.reset( new SfxItemSet( *pFormat->GetAttrSet().GetPool(), - pFormat->GetAttrSet().GetRanges() ) ); - pItemSet->Put( rTmpLang ); + if( !moItemSet ) + moItemSet.emplace( *pFormat->GetAttrSet().GetPool(), + pFormat->GetAttrSet().GetRanges() ); + moItemSet->Put( rTmpLang ); } } } @@ -562,19 +562,19 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, } // If necessary, take the hard attribute from the style - if( pFormatInfo->pItemSet ) + if( pFormatInfo->moItemSet ) { - OSL_ENSURE(!rInfo.pItemSet, "Where does this ItemSet come from?"); - rInfo.pItemSet.reset(new SfxItemSet( *pFormatInfo->pItemSet )); + OSL_ENSURE(!rInfo.moItemSet, "Where does this ItemSet come from?"); + rInfo.moItemSet.emplace( *pFormatInfo->moItemSet ); } // additionally, add the hard attribute from the paragraph if( pNodeItemSet ) { - if (rInfo.pItemSet) - rInfo.pItemSet->Put( *pNodeItemSet ); + if (rInfo.moItemSet) + rInfo.moItemSet->Put( *pNodeItemSet ); else - rInfo.pItemSet.reset(new SfxItemSet( *pNodeItemSet )); + rInfo.moItemSet.emplace( *pNodeItemSet ); } // we will need the lower spacing of the paragraph later on @@ -595,11 +595,11 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, else aULSpaceItem.SetUpper( rHWrt.m_nHeaderFooterSpace ); - if (!rInfo.pItemSet) + if (!rInfo.moItemSet) { - rInfo.pItemSet.reset(new SfxItemSet(*rFormat.GetAttrSet().GetPool(), svl::Items<RES_UL_SPACE, RES_UL_SPACE>)); + rInfo.moItemSet.emplace(*rFormat.GetAttrSet().GetPool(), svl::Items<RES_UL_SPACE, RES_UL_SPACE>); } - rInfo.pItemSet->Put( aULSpaceItem ); + rInfo.moItemSet->Put( aULSpaceItem ); } rHWrt.m_bOutHeader = false; rHWrt.m_bOutFooter = false; @@ -619,8 +619,8 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, const SfxPoolItem* pAdjItem = nullptr; const SfxPoolItem* pItem; - if( rInfo.pItemSet && - SfxItemState::SET == rInfo.pItemSet->GetItemState( RES_PARATR_ADJUST, + if( rInfo.moItemSet && + SfxItemState::SET == rInfo.moItemSet->GetItemState( RES_PARATR_ADJUST, false, &pItem ) ) { pAdjItem = pItem; @@ -812,12 +812,12 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, } LanguageType eLang; - if (rInfo.pItemSet) - eLang = static_cast<const SvxLanguageItem&>(rInfo.pItemSet->Get(SwHTMLWriter::GetLangWhichIdFromScript(rHWrt.m_nCSS1Script))).GetLanguage(); + if (rInfo.moItemSet) + eLang = static_cast<const SvxLanguageItem&>(rInfo.moItemSet->Get(SwHTMLWriter::GetLangWhichIdFromScript(rHWrt.m_nCSS1Script))).GetLanguage(); else eLang = rHWrt.m_eLang; - if( rInfo.pItemSet ) + if( rInfo.moItemSet ) { static const sal_uInt16 aWhichIds[3] = { RES_CHRATR_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_LANGUAGE }; @@ -825,10 +825,10 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, { // export language if it differs from the default language only. const SfxPoolItem *pTmpItem; - if( SfxItemState::SET == rInfo.pItemSet->GetItemState( i, + if( SfxItemState::SET == rInfo.moItemSet->GetItemState( i, true, &pTmpItem ) && static_cast<const SvxLanguageItem *>(pTmpItem)->GetLanguage() == eLang ) - rInfo.pItemSet->ClearItem( i ); + rInfo.moItemSet->ClearItem( i ); } } @@ -918,9 +918,9 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, pTextNd->GetAnyFormatColl().GetPoolFormatId(), pTextNd->GetText()) > -1; // and now, if necessary, the STYLE options - if (rHWrt.m_bCfgOutStyles && rInfo.pItemSet) + if (rHWrt.m_bCfgOutStyles && rInfo.moItemSet) { - OutCSS1_ParaTagStyleOpt( rWrt, *rInfo.pItemSet ); + OutCSS1_ParaTagStyleOpt( rWrt, *rInfo.moItemSet ); } if (rHWrt.m_bParaDotLeaders) { @@ -1652,9 +1652,9 @@ void HTMLEndPosLst::InsertNoScript( const SfxPoolItem& rItem, // attributes InsertItem( rItem, nStart, nEnd ); } - if( pFormatInfo->pItemSet ) + if( pFormatInfo->moItemSet ) { - Insert( *pFormatInfo->pItemSet, nStart, nEnd, + Insert( *pFormatInfo->moItemSet, nStart, nEnd, rFormatInfos, true, bParaAttrs ); } } @@ -2263,9 +2263,9 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const SwContentNode& rNode ) rHTMLWrt.m_xDfltColor, rHTMLWrt.m_bCfgOutStyles, rHTMLWrt.GetHTMLMode(), aFullText, rHTMLWrt.m_aScriptTextStyles ); - if( aFormatInfo.pItemSet ) + if( aFormatInfo.moItemSet ) { - aEndPosLst.Insert( *aFormatInfo.pItemSet, 0, nEnd + nOffset, + aEndPosLst.Insert( *aFormatInfo.moItemSet, 0, nEnd + nOffset, rHTMLWrt.m_CharFormatInfos, false, true ); } diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index 0af1003fa8d0..5365214b504d 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -24,6 +24,7 @@ #include <set> #include <string_view> #include <map> +#include <optional> #include <com/sun/star/container/XIndexContainer.hpp> #include <com/sun/star/form/XForm.hpp> @@ -213,7 +214,7 @@ struct SwHTMLFormatInfo OString aToken; // the token to output OUString aClass; // the class to output - std::unique_ptr<SfxItemSet> pItemSet; // the attribute set to output + std::optional<SfxItemSet> moItemSet; // the attribute set to output sal_Int32 nLeftMargin; // some default values for sal_Int32 nRightMargin; // paragraph styles diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx index 9dffac99c8c2..fe5e2174e7e4 100644 --- a/sw/source/filter/xml/xmlfmt.cxx +++ b/sw/source/filter/xml/xmlfmt.cxx @@ -384,7 +384,7 @@ public: class SwXMLItemSetStyleContext_Impl : public SvXMLStyleContext { OUString m_sMasterPageName; - std::unique_ptr<SfxItemSet> m_pItemSet; + std::optional<SfxItemSet> m_oItemSet; SwXMLTextStyleContext_Impl *m_pTextStyle; SvXMLStylesContext &m_rStyles; @@ -419,7 +419,7 @@ public: sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; // The item set may be empty! - SfxItemSet *GetItemSet() { return m_pItemSet.get(); } + SfxItemSet *GetItemSet() { return m_oItemSet ? &*m_oItemSet : nullptr; } bool HasMasterPageName() const { return m_bHasMasterPageName; } @@ -519,7 +519,7 @@ SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateItemSetContext( sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) { - OSL_ENSURE( !m_pItemSet, + OSL_ENSURE( !m_oItemSet, "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: item set exists" ); SvXMLImportContext *pContext = nullptr; @@ -530,29 +530,29 @@ SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateItemSetContext( switch( GetFamily() ) { case XmlStyleFamily::TABLE_TABLE: - m_pItemSet.reset( new SfxItemSet( rItemPool, aTableSetRange ) ); + m_oItemSet.emplace( rItemPool, aTableSetRange ); break; case XmlStyleFamily::TABLE_COLUMN: - m_pItemSet.reset( new SfxItemSet( rItemPool, svl::Items<RES_FRM_SIZE, RES_FRM_SIZE> ) ); + m_oItemSet.emplace( rItemPool, svl::Items<RES_FRM_SIZE, RES_FRM_SIZE> ); break; case XmlStyleFamily::TABLE_ROW: - m_pItemSet.reset( new SfxItemSet( rItemPool, aTableLineSetRange ) ); + m_oItemSet.emplace( rItemPool, aTableLineSetRange ); break; case XmlStyleFamily::TABLE_CELL: - m_pItemSet.reset( new SfxItemSet( rItemPool, aTableBoxSetRange ) ); + m_oItemSet.emplace( rItemPool, aTableBoxSetRange ); break; default: OSL_ENSURE( false, "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: unknown family" ); break; } - if( m_pItemSet ) + if( m_oItemSet ) pContext = GetSwImport().CreateTableItemImportContext( nElement, xAttrList, GetFamily(), - *m_pItemSet ); + *m_oItemSet ); if( !pContext ) { - m_pItemSet.reset(); + m_oItemSet.reset(); } return pContext; @@ -636,15 +636,15 @@ void SwXMLItemSetStyleContext_Impl::ConnectPageDesc() if( !pPageDesc ) return; - if( !m_pItemSet ) + if( !m_oItemSet ) { SfxItemPool& rItemPool = pDoc->GetAttrPool(); - m_pItemSet.reset( new SfxItemSet( rItemPool, aTableSetRange ) ); + m_oItemSet.emplace( rItemPool, aTableSetRange ); } const SfxPoolItem *pItem; std::unique_ptr<SwFormatPageDesc> pFormatPageDesc; - if( SfxItemState::SET == m_pItemSet->GetItemState( RES_PAGEDESC, false, + if( SfxItemState::SET == m_oItemSet->GetItemState( RES_PAGEDESC, false, &pItem ) ) { if( static_cast<const SwFormatPageDesc *>(pItem)->GetPageDesc() != pPageDesc ) @@ -656,7 +656,7 @@ void SwXMLItemSetStyleContext_Impl::ConnectPageDesc() if( pFormatPageDesc ) { pFormatPageDesc->RegisterToPageDesc( *pPageDesc ); - m_pItemSet->Put( *pFormatPageDesc ); + m_oItemSet->Put( *pFormatPageDesc ); } } @@ -672,15 +672,15 @@ bool SwXMLItemSetStyleContext_Impl::ResolveDataStyleName() // if the key is valid, insert Item into ItemSet if( -1 != nFormat ) { - if( !m_pItemSet ) + if( !m_oItemSet ) { SwDoc *pDoc = SwImport::GetDocFromXMLImport( GetSwImport() ); SfxItemPool& rItemPool = pDoc->GetAttrPool(); - m_pItemSet.reset( new SfxItemSet( rItemPool, aTableBoxSetRange ) ); + m_oItemSet.emplace( rItemPool, aTableBoxSetRange ); } SwTableBoxNumFormat aNumFormatItem(nFormat); - m_pItemSet->Put(aNumFormatItem); + m_oItemSet->Put(aNumFormatItem); } // now resolved