[Libreoffice-commits] core.git: cui/source desktop/source include/svx starmath/source svx/source

Julien Nabet serval2412 at yahoo.fr
Sun Nov 5 10:41:02 UTC 2017


 cui/source/dialogs/cuicharmap.cxx |   16 +++++-----------
 desktop/source/lib/init.cxx       |    4 ++--
 include/svx/ucsubset.hxx          |    3 +--
 starmath/source/dialog.cxx        |    7 +++----
 svx/source/dialog/charmap.cxx     |   13 ++-----------
 5 files changed, 13 insertions(+), 30 deletions(-)

New commits:
commit e567694246d99a2a99c4079b04ed2ad8cd5ed785
Author: Julien Nabet <serval2412 at yahoo.fr>
Date:   Sun Nov 5 08:39:47 2017 +0100

    Remove GetNextSubset and create GetSubsetMap
    
    To avoid to store an iterator and simplify loops
    
    Change-Id: I9b160714125176841961a56905d81dcb876c68b6
    Reviewed-on: https://gerrit.libreoffice.org/44326
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Julien Nabet <serval2412 at yahoo.fr>

diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx
index 1f039be57e85..1058b70a795d 100644
--- a/cui/source/dialogs/cuicharmap.cxx
+++ b/cui/source/dialogs/cuicharmap.cxx
@@ -609,12 +609,8 @@ void SvxCharacterMap::fillAllSubsets(ListBox &rListBox)
 {
     SubsetMap aAll(nullptr);
     rListBox.Clear();
-    bool bFirst = true;
-    while (const Subset *s = aAll.GetNextSubset(bFirst))
-    {
-        rListBox.InsertEntry( s->GetName() );
-        bFirst = false;
-    }
+    for (auto & subset : aAll.GetSubsetMap())
+        rListBox.InsertEntry( subset.GetName() );
 }
 
 
@@ -675,13 +671,11 @@ IMPL_LINK_NOARG(SvxCharacterMap, FontSelectHdl, ListBox&, void)
         pSubsetMap = new SubsetMap( xFontCharMap );
 
         // update subset listbox for new font's unicode subsets
-        // TODO: is it worth to improve the stupid linear search?
         bool bFirst = true;
-        const Subset* s;
-        while( nullptr != (s = pSubsetMap->GetNextSubset( bFirst ))  )
+        for (auto const& subset : pSubsetMap->GetSubsetMap())
         {
-            const sal_Int32 nPos_ = m_pSubsetLB->InsertEntry( s->GetName() );
-            m_pSubsetLB->SetEntryData( nPos_, const_cast<Subset *>(s) );
+            const sal_Int32 nPos_ = m_pSubsetLB->InsertEntry( subset.GetName() );
+            m_pSubsetLB->SetEntryData( nPos_, const_cast<Subset *>(&subset) );
             // NOTE: subset must live at least as long as the selected font
             if( bFirst )
                 m_pSubsetLB->SelectEntryPos( nPos_ );
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 906e271f5c30..96b6ab2e2399 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2525,10 +2525,10 @@ static char* getFontSubset (const OString& aFontName)
             aDevice->GetFontCharMap(xFontCharMap);
             SubsetMap aSubMap(xFontCharMap);
 
-            for(const Subset* pItSub = aSubMap.GetNextSubset(true); pItSub; pItSub = aSubMap.GetNextSubset(false))
+            for (auto const& subset : aSubMap.GetSubsetMap())
             {
                 boost::property_tree::ptree aChild;
-                aChild.put("", static_cast<int>(ublock_getCode(pItSub->GetRangeMin())));
+                aChild.put("", static_cast<int>(ublock_getCode(subset.GetRangeMin())));
                 aValues.push_back(std::make_pair("", aChild));
             }
         }
diff --git a/include/svx/ucsubset.hxx b/include/svx/ucsubset.hxx
index 570913f3bd18..ae5286ec3863 100644
--- a/include/svx/ucsubset.hxx
+++ b/include/svx/ucsubset.hxx
@@ -60,11 +60,10 @@ public:
     SubsetMap( const FontCharMapRef& );
 
     const Subset*   GetSubsetByUnicode( sal_UCS4 ) const;
-    const Subset*   GetNextSubset( bool bFirst ) const;
+    const SubsetList&   GetSubsetMap() const;
 
 private:
     SubsetList      maSubsets;
-    mutable SubsetList::const_iterator maSubsetIterator;
 
     SVX_DLLPRIVATE void            InitList();
     SVX_DLLPRIVATE void            ApplyCharMap( const FontCharMapRef& );
diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx
index ffde4194dbbd..f710aa1988f0 100644
--- a/starmath/source/dialog.cxx
+++ b/starmath/source/dialog.cxx
@@ -2257,11 +2257,10 @@ void SmSymDefineDialog::SetFont(const OUString &rFontName, const OUString &rStyl
 
     pFontsSubsetLB->Clear();
     bool bFirst = true;
-    const Subset* pSubset;
-    while( nullptr != (pSubset = pSubsetMap->GetNextSubset( bFirst )) )
+    for (auto & subset : pSubsetMap->GetSubsetMap())
     {
-        const sal_Int32 nPos = pFontsSubsetLB->InsertEntry( pSubset->GetName());
-        pFontsSubsetLB->SetEntryData( nPos, const_cast<Subset *>(pSubset) );
+        const sal_Int32 nPos = pFontsSubsetLB->InsertEntry( subset.GetName());
+        pFontsSubsetLB->SetEntryData( nPos, const_cast<Subset *>(&subset) );
         // subset must live at least as long as the selected font !!!
         if( bFirst )
             pFontsSubsetLB->SelectEntryPos( nPos );
diff --git a/svx/source/dialog/charmap.cxx b/svx/source/dialog/charmap.cxx
index b529e3a9ebfa..510ca605711a 100644
--- a/svx/source/dialog/charmap.cxx
+++ b/svx/source/dialog/charmap.cxx
@@ -960,18 +960,9 @@ SubsetMap::SubsetMap( const FontCharMapRef& rxFontCharMap )
     ApplyCharMap(rxFontCharMap);
 }
 
-const Subset* SubsetMap::GetNextSubset( bool bFirst ) const
+const SubsetList& SubsetMap::GetSubsetMap() const
 {
-    if( bFirst )
-    {
-        maSubsetIterator = maSubsets.begin();
-    }
-
-    if( maSubsetIterator == maSubsets.end() )
-        return nullptr;
-
-    const Subset* s = &*(maSubsetIterator++);
-    return s;
+    return maSubsets;
 }
 
 const Subset* SubsetMap::GetSubsetByUnicode( sal_UCS4 cChar ) const


More information about the Libreoffice-commits mailing list