[Libreoffice-commits] core.git: sc/inc sc/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 21 16:52:41 UTC 2021


 sc/inc/funcdesc.hxx              |   12 ++++++------
 sc/source/core/data/funcdesc.cxx |   34 ++++++++++++++++------------------
 2 files changed, 22 insertions(+), 24 deletions(-)

New commits:
commit 0ce2ba98aa3bde5dc91b00753b11d0add69925af
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jul 21 11:24:18 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Jul 21 18:52:07 2021 +0200

    flatten aCatLists in ScFunctionCategory
    
    no need to allocate the vector separately, they are always there, and
    initialise once
    
    Change-Id: I92c735502d26dc4ff9ab138e5086d74db3afb138
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119311
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/inc/funcdesc.hxx b/sc/inc/funcdesc.hxx
index 6568893be2fa..58c6957316b3 100644
--- a/sc/inc/funcdesc.hxx
+++ b/sc/inc/funcdesc.hxx
@@ -267,8 +267,8 @@ private:
 class ScFunctionCategory final : public formula::IFunctionCategory
 {
 public:
-    ScFunctionCategory(::std::vector<const ScFuncDesc*>* _pCategory,sal_uInt32 _nCategory)
-            : m_pCategory(_pCategory),m_nCategory(_nCategory){}
+    ScFunctionCategory(const ::std::vector<const ScFuncDesc*>& _rCategory,sal_uInt32 _nCategory)
+            : m_rCategory(_rCategory),m_nCategory(_nCategory){}
     virtual ~ScFunctionCategory(){}
 
     /**
@@ -293,7 +293,7 @@ public:
     virtual OUString getName() const override;
 
 private:
-    ::std::vector<const ScFuncDesc*>* m_pCategory; /**< list of functions in this category */
+    const ::std::vector<const ScFuncDesc*>& m_rCategory; /**< list of functions in this category */
     mutable OUString m_sName; /**< name of this category */
     sal_uInt32 m_nCategory; /**< index number of this category */
 };
@@ -394,10 +394,10 @@ public:
     virtual sal_Unicode getSingleToken(const formula::IFunctionManager::EToken _eToken) const override;
 
 private:
-    std::unique_ptr<std::vector<const ScFuncDesc*>> aCatLists[MAX_FUNCCAT]; /**< array of all categories, 0 is the cumulative ('All') category */
+    std::vector<const ScFuncDesc*> aCatLists[MAX_FUNCCAT]; /**< array of all categories, 0 is the cumulative ('All') category */
     mutable std::map< sal_uInt32, std::shared_ptr<ScFunctionCategory> > m_aCategories; /**< map of category pos to IFunctionCategory */
-    mutable std::vector<const ScFuncDesc*>::iterator pCurCatListIter; /**< position in current category */
-    mutable std::vector<const ScFuncDesc*>::iterator pCurCatListEnd; /**< end of current category */
+    mutable std::vector<const ScFuncDesc*>::const_iterator pCurCatListIter; /**< position in current category */
+    mutable std::vector<const ScFuncDesc*>::const_iterator pCurCatListEnd; /**< end of current category */
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/funcdesc.cxx b/sc/source/core/data/funcdesc.cxx
index c7ea3cc5f927..4f3187d078e8 100644
--- a/sc/source/core/data/funcdesc.cxx
+++ b/sc/source/core/data/funcdesc.cxx
@@ -1018,7 +1018,7 @@ const ScFuncDesc* ScFunctionList::GetFunction( sal_uInt32 nIndex ) const
 
 sal_uInt32 ScFunctionCategory::getCount() const
 {
-    return m_pCategory->size();
+    return m_rCategory.size();
 }
 
 OUString ScFunctionCategory::getName() const
@@ -1031,8 +1031,8 @@ OUString ScFunctionCategory::getName() const
 const formula::IFunctionDescription* ScFunctionCategory::getFunction(sal_uInt32 _nPos) const
 {
     const ScFuncDesc* pDesc = nullptr;
-    if(_nPos < m_pCategory->size())
-        pDesc = m_pCategory->at(_nPos);
+    if(_nPos < m_rCategory.size())
+        pDesc = m_rCategory.at(_nPos);
     return pDesc;
 }
 
@@ -1050,8 +1050,7 @@ ScFunctionMgr::ScFunctionMgr()
     OSL_ENSURE( pFuncList, "Functionlist not found." );
     sal_uInt32 catCount[MAX_FUNCCAT] = {0};
 
-    aCatLists[0].reset( new ::std::vector<const ScFuncDesc*> );
-    aCatLists[0]->reserve(pFuncList->GetCount());
+    aCatLists[0].reserve(pFuncList->GetCount());
 
     // Retrieve all functions, store in cumulative ("All") category, and count
     // number of functions in each category
@@ -1060,29 +1059,28 @@ ScFunctionMgr::ScFunctionMgr()
         OSL_ENSURE((pDesc->nCategory) < MAX_FUNCCAT, "Unknown category");
         if ((pDesc->nCategory) < MAX_FUNCCAT)
             ++catCount[pDesc->nCategory];
-        aCatLists[0]->push_back(pDesc);
+        aCatLists[0].push_back(pDesc);
     }
 
     // Sort functions in cumulative category by name
-    ::std::sort(aCatLists[0]->begin(), aCatLists[0]->end(), ScFuncDesc::compareByName);
+    ::std::sort(aCatLists[0].begin(), aCatLists[0].end(), ScFuncDesc::compareByName);
 
     // Allocate correct amount of space for categories
     for (sal_uInt16 i = 1; i < MAX_FUNCCAT; ++i)
     {
-        aCatLists[i].reset( new ::std::vector<const ScFuncDesc*> );
-        aCatLists[i]->reserve(catCount[i]);
+        aCatLists[i].reserve(catCount[i]);
     }
 
     // Fill categories with the corresponding functions (still sorted by name)
-    for (auto const& elemList : *aCatLists[0])
+    for (auto const& elemList : aCatLists[0])
     {
         if ((elemList->nCategory) < MAX_FUNCCAT)
-            aCatLists[elemList->nCategory]->push_back(elemList);
+            aCatLists[elemList->nCategory].push_back(elemList);
     }
 
     // Initialize iterators
-    pCurCatListIter = aCatLists[0]->end();
-    pCurCatListEnd = aCatLists[0]->end();
+    pCurCatListIter = aCatLists[0].end();
+    pCurCatListEnd = aCatLists[0].end();
 }
 
 ScFunctionMgr::~ScFunctionMgr()
@@ -1105,14 +1103,14 @@ const ScFuncDesc* ScFunctionMgr::First( sal_uInt16 nCategory ) const
     const ScFuncDesc* pDesc = nullptr;
     if ( nCategory < MAX_FUNCCAT )
     {
-        pCurCatListIter = aCatLists[nCategory]->begin();
-        pCurCatListEnd = aCatLists[nCategory]->end();
+        pCurCatListIter = aCatLists[nCategory].begin();
+        pCurCatListEnd = aCatLists[nCategory].end();
         pDesc = *pCurCatListIter;
     }
     else
     {
-        pCurCatListIter = aCatLists[0]->end();
-        pCurCatListEnd = aCatLists[0]->end();
+        pCurCatListIter = aCatLists[0].end();
+        pCurCatListEnd = aCatLists[0].end();
     }
     return pDesc;
 }
@@ -1140,7 +1138,7 @@ const formula::IFunctionCategory* ScFunctionMgr::getCategory(sal_uInt32 nCategor
     if ( nCategory < (MAX_FUNCCAT-1) )
     {
         if (m_aCategories.find(nCategory) == m_aCategories.end())
-            m_aCategories[nCategory] = std::make_shared<ScFunctionCategory>(aCatLists[nCategory+1].get(),nCategory); // aCatLists[0] is "all"
+            m_aCategories[nCategory] = std::make_shared<ScFunctionCategory>(aCatLists[nCategory+1],nCategory); // aCatLists[0] is "all"
         return m_aCategories[nCategory].get();
     }
     return nullptr;


More information about the Libreoffice-commits mailing list