[Libreoffice-commits] core.git: 2 commits - editeng/source include/editeng sc/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 20 06:56:31 UTC 2021


 editeng/source/uno/unoforou.cxx  |   24 ++++++++++++------------
 include/editeng/unoforou.hxx     |    6 ++++--
 sc/source/core/data/column2.cxx  |   14 +++++++-------
 sc/source/core/data/documen2.cxx |    6 +++---
 sc/source/core/data/documen8.cxx |    8 ++++----
 5 files changed, 30 insertions(+), 28 deletions(-)

New commits:
commit a64e503b77679d60997a2b6c69b7f1cd37aba5e9
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun Sep 19 20:50:57 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Sep 20 08:56:03 2021 +0200

    no need to allocate these SfxItemSet on the heap
    
    Change-Id: I2aa7f9e8f8bc93f7422acfaac2337087060d36a4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122328
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index dfcce828e1e4..658a37b983d4 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -388,22 +388,22 @@ tools::Long ScColumn::GetNeededSize(
         pDev->SetMapMode( aHMMMode );
         pEngine->SetRefDevice( pDev );
         rDocument.ApplyAsianEditSettings( *pEngine );
-        std::unique_ptr<SfxItemSet> pSet(new SfxItemSet( pEngine->GetEmptyItemSet() ));
+        SfxItemSet aSet( pEngine->GetEmptyItemSet() );
         if ( ScStyleSheet* pPreviewStyle = rDocument.GetPreviewCellStyle( nCol, nRow, nTab ) )
         {
             ScPatternAttr aPreviewPattern( *pPattern );
             aPreviewPattern.SetStyleSheet(pPreviewStyle);
-            aPreviewPattern.FillEditItemSet( pSet.get(), pCondSet );
+            aPreviewPattern.FillEditItemSet( &aSet, pCondSet );
         }
         else
         {
             SfxItemSet* pFontSet = rDocument.GetPreviewFont( nCol, nRow, nTab );
-            pPattern->FillEditItemSet( pSet.get(), pFontSet ? pFontSet : pCondSet );
+            pPattern->FillEditItemSet( &aSet, pFontSet ? pFontSet : pCondSet );
         }
 //          no longer needed, are set with the text (is faster)
 //          pEngine->SetDefaults( pSet );
 
-        if ( pSet->Get(EE_PARA_HYPHENATE).GetValue() ) {
+        if ( aSet.Get(EE_PARA_HYPHENATE).GetValue() ) {
 
             css::uno::Reference<css::linguistic2::XHyphenator> xXHyphenator( LinguMgr::GetHyphenator() );
             pEngine->SetHyphenator( xXHyphenator );
@@ -456,7 +456,7 @@ tools::Long ScColumn::GetNeededSize(
 
         if (aCell.meType == CELLTYPE_EDIT)
         {
-            pEngine->SetTextNewDefaults(*aCell.mpEditText, std::move(pSet));
+            pEngine->SetTextNewDefaults(*aCell.mpEditText, std::move(aSet));
         }
         else
         {
@@ -467,9 +467,9 @@ tools::Long ScColumn::GetNeededSize(
                 rOptions.bFormula);
 
             if (!aString.isEmpty())
-                pEngine->SetTextNewDefaults(aString, std::move(pSet));
+                pEngine->SetTextNewDefaults(aString, std::move(aSet));
             else
-                pEngine->SetDefaults(std::move(pSet));
+                pEngine->SetDefaults(std::move(aSet));
         }
 
         bool bEngineVertical = pEngine->IsEffectivelyVertical();
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 8f77cb70ac46..dca102c16c89 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -478,9 +478,9 @@ ScNoteEditEngine& ScDocument::GetNoteEngine()
         mpNoteEngine->SetRefMapMode(MapMode(MapUnit::Map100thMM));
         ApplyAsianEditSettings( *mpNoteEngine );
         const SfxItemSet& rItemSet = GetDefPattern()->GetItemSet();
-        std::unique_ptr<SfxItemSet> pEEItemSet(new SfxItemSet( mpNoteEngine->GetEmptyItemSet() ));
-        ScPatternAttr::FillToEditItemSet( *pEEItemSet, rItemSet );
-        mpNoteEngine->SetDefaults( std::move(pEEItemSet) );      // edit engine takes ownership
+        SfxItemSet aEEItemSet( mpNoteEngine->GetEmptyItemSet() );
+        ScPatternAttr::FillToEditItemSet( aEEItemSet, rItemSet );
+        mpNoteEngine->SetDefaults( std::move(aEEItemSet) );      // edit engine takes ownership
     }
     return *mpNoteEngine;
 }
diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx
index 02148af2fdbd..1553c26c0f3e 100644
--- a/sc/source/core/data/documen8.cxx
+++ b/sc/source/core/data/documen8.cxx
@@ -1250,19 +1250,19 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, Transliteratio
 
                     // defaults from cell attributes must be set so right language is used
                     const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
-                    std::unique_ptr<SfxItemSet> pDefaults(new SfxItemSet( pEngine->GetEmptyItemSet() ));
+                    SfxItemSet aDefaults( pEngine->GetEmptyItemSet() );
                     if ( ScStyleSheet* pPreviewStyle = GetPreviewCellStyle( nCol, nRow, nTab ) )
                     {
                         ScPatternAttr aPreviewPattern( *pPattern );
                         aPreviewPattern.SetStyleSheet(pPreviewStyle);
-                        aPreviewPattern.FillEditItemSet( pDefaults.get() );
+                        aPreviewPattern.FillEditItemSet( &aDefaults );
                     }
                     else
                     {
                         SfxItemSet* pFontSet = GetPreviewFont( nCol, nRow, nTab );
-                        pPattern->FillEditItemSet( pDefaults.get(), pFontSet );
+                        pPattern->FillEditItemSet( &aDefaults, pFontSet );
                     }
-                    pEngine->SetDefaults( std::move(pDefaults) );
+                    pEngine->SetDefaults( std::move(aDefaults) );
                     if (aCell.meType == CELLTYPE_STRING)
                         pEngine->SetTextCurrentDefaults(aCell.mpString->getString());
                     else if (aCell.mpEditText)
commit 494358661a05ce548d09e51703f72cd2c012437b
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sun Sep 19 20:40:10 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Sep 20 08:55:56 2021 +0200

    no need to allocate SfxItemSet separately in SvxOutlinerForwarder
    
    Change-Id: I6042993749b5e0b841e82e3b6930e656b88c7fd7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122327
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/editeng/source/uno/unoforou.cxx b/editeng/source/uno/unoforou.cxx
index 21ffb0df2976..7edf6923dec1 100644
--- a/editeng/source/uno/unoforou.cxx
+++ b/editeng/source/uno/unoforou.cxx
@@ -94,18 +94,18 @@ static SfxItemSet ImplOutlinerForwarderGetAttribs( const ESelection& rSel, EditE
 
 SfxItemSet SvxOutlinerForwarder::GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib ) const
 {
-    if( mpAttribsCache && ( EditEngineAttribs::All == nOnlyHardAttrib ) )
+    if( moAttribsCache && ( EditEngineAttribs::All == nOnlyHardAttrib ) )
     {
         // have we the correct set in cache?
         if( maAttribCacheSelection == rSel )
         {
             // yes! just return the cache
-            return *mpAttribsCache;
+            return *moAttribsCache;
         }
         else
         {
             // no, we need delete the old cache
-            mpAttribsCache.reset();
+            moAttribsCache.reset();
         }
     }
 
@@ -117,7 +117,7 @@ SfxItemSet SvxOutlinerForwarder::GetAttribs( const ESelection& rSel, EditEngineA
 
     if( EditEngineAttribs::All == nOnlyHardAttrib )
     {
-        mpAttribsCache.reset(new SfxItemSet( aSet ));
+        moAttribsCache.emplace( aSet );
         maAttribCacheSelection = rSel;
     }
 
@@ -130,31 +130,31 @@ SfxItemSet SvxOutlinerForwarder::GetAttribs( const ESelection& rSel, EditEngineA
 
 SfxItemSet SvxOutlinerForwarder::GetParaAttribs( sal_Int32 nPara ) const
 {
-    if( mpParaAttribsCache )
+    if( moParaAttribsCache )
     {
         // have we the correct set in cache?
         if( nPara == mnParaAttribsCache )
         {
             // yes! just return the cache
-            return *mpParaAttribsCache;
+            return *moParaAttribsCache;
         }
         else
         {
             // no, we need delete the old cache
-            mpParaAttribsCache.reset();
+            moParaAttribsCache.reset();
         }
     }
 
-    mpParaAttribsCache.reset(new SfxItemSet( rOutliner.GetParaAttribs( nPara ) ));
+    moParaAttribsCache.emplace( rOutliner.GetParaAttribs( nPara ) );
     mnParaAttribsCache = nPara;
 
     EditEngine& rEditEngine = const_cast<EditEngine&>(rOutliner.GetEditEngine());
 
     SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( nPara );
     if( pStyle )
-        mpParaAttribsCache->SetParent( &(pStyle->GetItemSet() ) );
+        moParaAttribsCache->SetParent( &(pStyle->GetItemSet() ) );
 
-    return *mpParaAttribsCache;
+    return *moParaAttribsCache;
 }
 
 void SvxOutlinerForwarder::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet )
@@ -247,8 +247,8 @@ SfxItemState SvxOutlinerForwarder::GetItemState( sal_Int32 nPara, sal_uInt16 nWh
 
 void SvxOutlinerForwarder::flushCache()
 {
-    mpAttribsCache.reset();
-    mpParaAttribsCache.reset();
+    moAttribsCache.reset();
+    moParaAttribsCache.reset();
 }
 
 LanguageType SvxOutlinerForwarder::GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const
diff --git a/include/editeng/unoforou.hxx b/include/editeng/unoforou.hxx
index 4695077fa7c7..bbc92541735c 100644
--- a/include/editeng/unoforou.hxx
+++ b/include/editeng/unoforou.hxx
@@ -23,7 +23,9 @@
 #include <editeng/unoedsrc.hxx>
 #include <editeng/editengdllapi.h>
 #include <editeng/editdata.hxx>
+#include <svl/itemset.hxx>
 #include <memory>
+#include <optional>
 
 class Outliner;
 
@@ -37,14 +39,14 @@ private:
 
     /** this pointer may be null or point to an item set for the attribs of
         the selection maAttribsSelection */
-    mutable std::unique_ptr<SfxItemSet> mpAttribsCache;
+    mutable std::optional<SfxItemSet> moAttribsCache;
 
     /** if we have a cached attribute item set, this is the selection of it */
     mutable ESelection  maAttribCacheSelection;
 
     /** this pointer may be null or point to an item set for the paragraph
         mnParaAttribsCache */
-    mutable std::unique_ptr<SfxItemSet> mpParaAttribsCache;
+    mutable std::optional<SfxItemSet> moParaAttribsCache;
 
     /** if we have a cached para attribute item set, this is the paragraph of it */
     mutable sal_Int32   mnParaAttribsCache;


More information about the Libreoffice-commits mailing list