summaryrefslogtreecommitdiff
path: root/fpicker
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-12-06 09:46:45 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2018-12-06 18:07:55 +0100
commitff8c49236b8c2498b1c186192fc6ab6ce076d21a (patch)
tree1e3cb9b25265343d5614fd5b20fa072265a172d9 /fpicker
parent2edc86a592bc943fcffef0a8ae8db220e18e2b37 (diff)
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@collabora.com>
Diffstat (limited to 'fpicker')
-rw-r--r--fpicker/source/win32/FilterContainer.cxx23
-rw-r--r--fpicker/source/win32/FilterContainer.hxx7
-rw-r--r--fpicker/source/win32/VistaFilePickerImpl.cxx20
3 files changed, 25 insertions, 25 deletions
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();