sw/inc/sortopt.hxx                |    2 -
 sw/source/core/doc/docsort.cxx    |   18 ++++++++--------
 sw/source/core/doc/sortopt.cxx    |    5 ----
 sw/source/core/unocore/unoobj.cxx |   42 +++++++++++++++++++-------------------
 sw/source/ui/misc/srtdlg.cxx      |   12 +++++-----
 5 files changed, 38 insertions(+), 41 deletions(-)

New commits:
commit 0bb2985071780ab3c83e576b1f57841fd037eaba
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri May 28 11:23:11 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat May 29 10:06:50 2021 +0200

    no need to store SwSortKey separately on the heap
    
    Change-Id: Ib05e02a6c9c239f590508c7e71667d7ecca64f79
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116366
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/sortopt.hxx b/sw/inc/sortopt.hxx
index b29460f1f647..41667ce91f77 100644
--- a/sw/inc/sortopt.hxx
+++ b/sw/inc/sortopt.hxx
@@ -47,7 +47,7 @@ struct SW_DLLPUBLIC SwSortOptions
 
     SwSortOptions& operator=( SwSortOptions const & ) = delete; // MSVC2015 
workaround
 
-    std::vector<std::unique_ptr<SwSortKey>> aKeys;
+    std::vector<SwSortKey>  aKeys;
     SwSortDirection         eDirection;
     sal_Unicode             cDeli;
     LanguageType            nLanguage;
diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx
index 3c2f8c1f019c..090385d6c419 100644
--- a/sw/source/core/doc/docsort.cxx
+++ b/sw/source/core/doc/docsort.cxx
@@ -121,8 +121,8 @@ int SwSortElement::keycompare(const SwSortElement& rCmp, 
sal_uInt16 nKey) const
     // The actual comparison
     const SwSortElement *pOrig, *pCmp;
 
-    const SwSortKey* pSrtKey = pOptions->aKeys[ nKey ].get();
-    if( pSrtKey->eSortOrder == SwSortOrder::Ascending )
+    const SwSortKey& rSrtKey = pOptions->aKeys[ nKey ];
+    if( rSrtKey.eSortOrder == SwSortOrder::Ascending )
     {
         pOrig = this;
         pCmp = &rCmp;
@@ -133,7 +133,7 @@ int SwSortElement::keycompare(const SwSortElement& rCmp, 
sal_uInt16 nKey) const
         pCmp = this;
     }
 
-    if( pSrtKey->bIsNumeric )
+    if( rSrtKey.bIsNumeric )
     {
         double n1 = pOrig->GetValue( nKey );
         double n2 = pCmp->GetValue( nKey );
@@ -142,12 +142,12 @@ int SwSortElement::keycompare(const SwSortElement& rCmp, 
sal_uInt16 nKey) const
     }
     else
     {
-        if( !pLastAlgorithm || *pLastAlgorithm != pSrtKey->sSortType )
+        if( !pLastAlgorithm || *pLastAlgorithm != rSrtKey.sSortType )
         {
             if( pLastAlgorithm )
-                *pLastAlgorithm = pSrtKey->sSortType;
+                *pLastAlgorithm = rSrtKey.sSortType;
             else
-                pLastAlgorithm = new OUString( pSrtKey->sSortType );
+                pLastAlgorithm = new OUString( rSrtKey.sSortType );
             pSortCollator->loadCollatorAlgorithm( *pLastAlgorithm,
                     *pLocale,
                     pOptions->bIgnoreCase ? SW_COLLATOR_IGNORES : 0 );
@@ -196,7 +196,7 @@ OUString SwSortTextElement::GetKey(sal_uInt16 nId) const
     const OUString& rStr = pTextNd->GetText();
 
     sal_Unicode nDeli = pOptions->cDeli;
-    sal_uInt16 nDCount = pOptions->aKeys[nId]->nColumnId, i = 1;
+    sal_uInt16 nDCount = pOptions->aKeys[nId].nColumnId, i = 1;
     sal_Int32 nStart = 0;
 
     // Find the delimiter
@@ -228,7 +228,7 @@ SwSortBoxElement::SwSortBoxElement( sal_uInt16 nRC )
 OUString SwSortBoxElement::GetKey(sal_uInt16 nKey) const
 {
     const FndBox_* pFndBox;
-    sal_uInt16 nCol = pOptions->aKeys[nKey]->nColumnId-1;
+    sal_uInt16 nCol = pOptions->aKeys[nKey].nColumnId-1;
 
     if( SwSortDirection::Rows == pOptions->eDirection )
         pFndBox = pBox->GetBox(nCol, nRow);         // Sort rows
@@ -260,7 +260,7 @@ OUString SwSortBoxElement::GetKey(sal_uInt16 nKey) const
 double SwSortBoxElement::GetValue( sal_uInt16 nKey ) const
 {
     const FndBox_* pFndBox;
-    sal_uInt16 nCol = pOptions->aKeys[nKey]->nColumnId-1;
+    sal_uInt16 nCol = pOptions->aKeys[nKey].nColumnId-1;
 
     if( SwSortDirection::Rows == pOptions->eDirection )
         pFndBox = pBox->GetBox(nCol, nRow);         // Sort rows
diff --git a/sw/source/core/doc/sortopt.cxx b/sw/source/core/doc/sortopt.cxx
index 06ac058568af..b5fc62ba845d 100644
--- a/sw/source/core/doc/sortopt.cxx
+++ b/sw/source/core/doc/sortopt.cxx
@@ -45,16 +45,13 @@ SwSortOptions::SwSortOptions()
 }
 
 SwSortOptions::SwSortOptions(const SwSortOptions& rOpt) :
+    aKeys( rOpt.aKeys ),
     eDirection( rOpt.eDirection ),
     cDeli( rOpt.cDeli ),
     nLanguage( rOpt.nLanguage ),
     bTable( rOpt.bTable ),
     bIgnoreCase( rOpt.bIgnoreCase )
 {
-    for(auto const & pKey : rOpt.aKeys)
-    {
-        aKeys.push_back( std::make_unique<SwSortKey>(*pKey) );
-    }
 }
 
 SwSortOptions::~SwSortOptions()
diff --git a/sw/source/core/unocore/unoobj.cxx 
b/sw/source/core/unocore/unoobj.cxx
index eeff66995bd3..56ad0c297eec 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -2588,21 +2588,21 @@ bool SwUnoCursorHelper::ConvertSortProperties(
     rSortOpt.cDeli = ' ';
     rSortOpt.eDirection = SwSortDirection::Columns;  //!! UI text may be 
contrary though !!
 
-    std::unique_ptr<SwSortKey> pKey1(new SwSortKey);
-    pKey1->nColumnId = USHRT_MAX;
-    pKey1->bIsNumeric = true;
-    pKey1->eSortOrder = SwSortOrder::Ascending;
-
-    std::unique_ptr<SwSortKey> pKey2(new SwSortKey);
-    pKey2->nColumnId = USHRT_MAX;
-    pKey2->bIsNumeric = true;
-    pKey2->eSortOrder = SwSortOrder::Ascending;
-
-    std::unique_ptr<SwSortKey> pKey3(new SwSortKey);
-    pKey3->nColumnId = USHRT_MAX;
-    pKey3->bIsNumeric = true;
-    pKey3->eSortOrder = SwSortOrder::Ascending;
-    SwSortKey* aKeys[3] = {pKey1.get(), pKey2.get(), pKey3.get()};
+    SwSortKey aKey1;
+    aKey1.nColumnId = USHRT_MAX;
+    aKey1.bIsNumeric = true;
+    aKey1.eSortOrder = SwSortOrder::Ascending;
+
+    SwSortKey aKey2;
+    aKey2.nColumnId = USHRT_MAX;
+    aKey2.bIsNumeric = true;
+    aKey2.eSortOrder = SwSortOrder::Ascending;
+
+    SwSortKey aKey3;
+    aKey3.nColumnId = USHRT_MAX;
+    aKey3.bIsNumeric = true;
+    aKey3.eSortOrder = SwSortOrder::Ascending;
+    SwSortKey* aKeys[3] = {&aKey1, &aKey2, &aKey3};
 
     bool bOldSortdescriptor(false);
     bool bNewSortdescriptor(false);
@@ -2813,17 +2813,17 @@ bool SwUnoCursorHelper::ConvertSortProperties(
         bRet = false;
     }
 
-    if (pKey1->nColumnId != USHRT_MAX)
+    if (aKey1.nColumnId != USHRT_MAX)
     {
-        rSortOpt.aKeys.push_back(std::move(pKey1));
+        rSortOpt.aKeys.push_back(aKey1);
     }
-    if (pKey2->nColumnId != USHRT_MAX)
+    if (aKey2.nColumnId != USHRT_MAX)
     {
-        rSortOpt.aKeys.push_back(std::move(pKey2));
+        rSortOpt.aKeys.push_back(aKey2);
     }
-    if (pKey3->nColumnId != USHRT_MAX)
+    if (aKey3.nColumnId != USHRT_MAX)
     {
-        rSortOpt.aKeys.push_back(std::move(pKey3));
+        rSortOpt.aKeys.push_back(aKey3);
     }
 
     return bRet && !rSortOpt.aKeys.empty();
diff --git a/sw/source/ui/misc/srtdlg.cxx b/sw/source/ui/misc/srtdlg.cxx
index 5f03f9c6ea56..52ca7ba66246 100644
--- a/sw/source/ui/misc/srtdlg.cxx
+++ b/sw/source/ui/misc/srtdlg.cxx
@@ -259,8 +259,8 @@ void SwSortDlg::Apply()
             sEntry = m_xTypDLB1->get_active_id();
 
         aOptions.aKeys.push_back(
-            std::make_unique<SwSortKey>( nCol1, sEntry,
-                                    bAsc1 ? SwSortOrder::Ascending : 
SwSortOrder::Descending ));
+            SwSortKey( nCol1, sEntry,
+                       bAsc1 ? SwSortOrder::Ascending : 
SwSortOrder::Descending ));
     }
 
     if( bCheck2 )
@@ -272,8 +272,8 @@ void SwSortDlg::Apply()
             sEntry = m_xTypDLB2->get_active_id();
 
         aOptions.aKeys.push_back(
-            std::make_unique<SwSortKey>( nCol2, sEntry,
-                                    bAsc2 ? SwSortOrder::Ascending : 
SwSortOrder::Descending ));
+            SwSortKey( nCol2, sEntry,
+                        bAsc2 ? SwSortOrder::Ascending : 
SwSortOrder::Descending ));
     }
 
     if( bCheck3 )
@@ -285,8 +285,8 @@ void SwSortDlg::Apply()
             sEntry = m_xTypDLB3->get_active_id();
 
         aOptions.aKeys.push_back(
-            std::make_unique<SwSortKey>( nCol3, sEntry,
-                                    bAsc3 ? SwSortOrder::Ascending : 
SwSortOrder::Descending ));
+            SwSortKey( nCol3, sEntry,
+                       bAsc3 ? SwSortOrder::Ascending : 
SwSortOrder::Descending ));
     }
 
     aOptions.eDirection =  bCol ? SwSortDirection::Columns : 
SwSortDirection::Rows;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to