[Libreoffice-commits] core.git: fpicker/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Dec 6 17:08:20 UTC 2018


 fpicker/source/win32/FilterContainer.cxx     |   23 +++++++++++++----------
 fpicker/source/win32/FilterContainer.hxx     |    7 ++++---
 fpicker/source/win32/VistaFilePickerImpl.cxx |   20 ++++++++------------
 3 files changed, 25 insertions(+), 25 deletions(-)

New commits:
commit ff8c49236b8c2498b1c186192fc6ab6ce076d21a
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Dec 6 09:46:45 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Dec 6 18:07:55 2018 +0100

    Optimize getting filter mask by index from CFilterContainer
    
    Change-Id: Id4ea2c3dd7420954b1852021f136bc98f20a9846
    Reviewed-on: https://gerrit.libreoffice.org/64663
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/fpicker/source/win32/FilterContainer.cxx b/fpicker/source/win32/FilterContainer.cxx
index a9a85f3ca48e..4fabed1460e4 100644
--- a/fpicker/source/win32/FilterContainer.cxx
+++ b/fpicker/source/win32/FilterContainer.cxx
@@ -99,33 +99,36 @@ void CFilterContainer::empty()
 // Precondition: the container is not empty
 //               there is a filter identified by the name
 
-bool CFilterContainer::getFilter( const OUString& aName, OUString& theFilter ) const
+bool CFilterContainer::getFilterByName(const OUString& aName, OUString& theFilter) const
 {
     OSL_PRECOND( !m_vFilters.empty() , "Empty filter container" );
+    return getFilterByIndex(getFilterTagPos(aName), theFilter);
+}
 
-    sal_Int32 pos = getFilterTagPos( aName );
+bool CFilterContainer::getFilterByIndex(sal_Int32 aIndex, OUString& theFilter) const
+{
+    bool bRet = true;
 
     try
     {
-        if ( pos > -1 )
-            theFilter = m_vFilters.at( pos ).second;
+        theFilter = m_vFilters.at(aIndex).second;
     }
-    catch( std::out_of_range& )
+    catch (std::out_of_range&)
     {
-        OSL_FAIL( "Filter not in filter container" );
-        pos = -1;
+        OSL_FAIL("Filter index out of range");
+        bRet = false;
     }
 
-    return pos > -1;
+    return bRet;
 }
 
-bool CFilterContainer::getFilter( sal_Int32 aIndex, OUString& theFilter ) const
+bool CFilterContainer::getFilterNameByIndex(sal_Int32 aIndex, OUString& theName) const
 {
     bool bRet = true;
 
     try
     {
-        theFilter = m_vFilters.at( aIndex ).first;
+        theName = m_vFilters.at(aIndex).first;
     }
     catch( std::out_of_range& )
     {
diff --git a/fpicker/source/win32/FilterContainer.hxx b/fpicker/source/win32/FilterContainer.hxx
index 89c3987aca45..f54b10a7f3f0 100644
--- a/fpicker/source/win32/FilterContainer.hxx
+++ b/fpicker/source/win32/FilterContainer.hxx
@@ -58,11 +58,12 @@ public:
     // clear all entries
     void empty( );
 
-    // retrieve a filter from the container both methods
+    // retrieve a filter from the container. These methods
     // return true on success and false if the specified
     // filter was not found
-    bool getFilter( const OUString& aName, OUString& theFilter ) const;
-    bool getFilter( sal_Int32 aIndex, OUString& theFilter ) const;
+    bool getFilterByName(const OUString& aName, OUString& theFilter) const;
+    bool getFilterByIndex(sal_Int32 aIndex, OUString& theFilter) const;
+    bool getFilterNameByIndex(sal_Int32 aIndex, OUString& theName) const;
 
     // returns the position of the specified filter or -1
     // if the filter was not found
diff --git a/fpicker/source/win32/VistaFilePickerImpl.cxx b/fpicker/source/win32/VistaFilePickerImpl.cxx
index 6c168a244fa0..1bd177f1d7f4 100644
--- a/fpicker/source/win32/VistaFilePickerImpl.cxx
+++ b/fpicker/source/win32/VistaFilePickerImpl.cxx
@@ -428,7 +428,7 @@ void VistaFilePickerImpl::impl_sta_getCurrentFilter(const RequestRef& rRequest)
     ::sal_Int32     nRealIndex = (nIndex-1); // COM dialog base on 1 ... filter container on 0 .-)
     if (
         (nRealIndex >= 0                         ) &&
-        (m_lFilters.getFilter(nRealIndex, sTitle))
+        (m_lFilters.getFilterNameByIndex(nRealIndex, sTitle))
        )
         rRequest->setArgument(PROP_FILTER_TITLE, sTitle);
     else if ( nRealIndex == -1 ) // Dialog not visible yet
@@ -1003,16 +1003,12 @@ void VistaFilePickerImpl::impl_sta_ShowDialogModal(const RequestRef& rRequest)
                     {
                         // COM dialog base on 1 ... filter container on 0 .-)
                         ::size_t nRealIndex = (nFileType-1);
-                        std::vector<OUString> vStrings;
-                        ::std::vector<COMDLG_FILTERSPEC> lFilters
-                            = lcl_buildFilterList(m_lFilters, vStrings);
-                        if ( nRealIndex < lFilters.size() )
+                        OUString sFilter;
+                        if (m_lFilters.getFilterByIndex(nRealIndex, sFilter))
                         {
-                            PCWSTR lpFilterExt = lFilters[nRealIndex].pszSpec;
-
-                            lpFilterExt = wcsrchr( lpFilterExt, '.' );
-                            if ( lpFilterExt )
-                                aFileURL += o3tl::toU(lpFilterExt);
+                            const sal_Int32 idx = sFilter.indexOf('.');
+                            if (idx >= 0)
+                                aFileURL += sFilter.copy(idx);
                         }
                     }
                 }
@@ -1285,7 +1281,7 @@ void VistaFilePickerImpl::impl_SetDefaultExtension( const OUString& currentFilte
    if (currentFilter.getLength())
    {
         OUString FilterExt;
-        m_lFilters.getFilter(currentFilter, FilterExt);
+        m_lFilters.getFilterByName(currentFilter, FilterExt);
 
         sal_Int32 posOfPoint = FilterExt.indexOf(L'.');
         const sal_Unicode* pFirstExtStart = FilterExt.getStr() + posOfPoint + 1;
@@ -1306,7 +1302,7 @@ void VistaFilePickerImpl::onAutoExtensionChanged (bool bChecked)
 
     const OUString sFilter = m_lFilters.getCurrentFilter ();
           OUString sExt    ;
-    if ( !m_lFilters.getFilter (sFilter, sExt))
+    if (!m_lFilters.getFilterByName(sFilter, sExt))
         return;
 
     TFileDialog iDialog = impl_getBaseDialogInterface();


More information about the Libreoffice-commits mailing list