scaddins/source/datefunc/datefunc.cxx | 91 +++++++++++++++------------------- scaddins/source/datefunc/datefunc.hxx | 45 ++-------------- 2 files changed, 47 insertions(+), 89 deletions(-)
New commits: commit 46ae639272baac0fda61b456a44d5d1307d7b230 Author: Ian <ian.gil...@gmail.com> Date: Fri Aug 7 17:02:11 2015 +0100 tdf#90222: Removed ScaFuncDataList type This type was a special case of a custom implemented list, and was used like a map. I have replaced it with a std::map typedef'd as ScaFuncDataMap. Since the map key also exists in the value object, there are more memory-efficient ways to implement this with a vector and a predicate functor for searching at the cost of some code complexity. I opted for the simpler code afforded by using a std::map implementation. Change-Id: Idd450f4a908ff503cb02e8e363ddbe3512903f47 Reviewed-on: https://gerrit.libreoffice.org/17579 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noelgran...@gmail.com> diff --git a/scaddins/source/datefunc/datefunc.cxx b/scaddins/source/datefunc/datefunc.cxx index f3fe9a8..5b48c90 100644 --- a/scaddins/source/datefunc/datefunc.cxx +++ b/scaddins/source/datefunc/datefunc.cxx @@ -26,6 +26,7 @@ #include <rtl/ustrbuf.hxx> #include <tools/rcid.h> #include <tools/resmgr.hxx> +#include <utility> using namespace ::com::sun::star; @@ -118,35 +119,14 @@ sal_uInt16 ScaFuncData::GetStrIndex( sal_uInt16 nParam ) const } -ScaFuncDataList::ScaFuncDataList( ResMgr& rResMgr ) : - nLast( 0xFFFFFFFF ) +void InitScaFuncDataMap( ScaFuncDataMap& rMap, ResMgr& rResMgr ) { for( sal_uInt16 nIndex = 0; nIndex < SAL_N_ELEMENTS(pFuncDataArr); nIndex++ ) - Append( new ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) ); -} - -ScaFuncDataList::~ScaFuncDataList() -{ - for( ScaFuncData* pFData = First(); pFData; pFData = Next() ) - delete pFData; -} - -const ScaFuncData* ScaFuncDataList::Get( const OUString& rProgrammaticName ) const -{ - if( aLastName == rProgrammaticName ) - return Get( nLast ); - - for( sal_uInt32 nIndex = 0; nIndex < Count(); nIndex++ ) { - const ScaFuncData* pCurr = Get( nIndex ); - if( pCurr->Is( rProgrammaticName ) ) - { - const_cast< ScaFuncDataList* >( this )->aLastName = rProgrammaticName; - const_cast< ScaFuncDataList* >( this )->nLast = nIndex; - return pCurr; - } + rMap.insert( std::make_pair( + OUString::createFromAscii(pFuncDataArr[ nIndex ].pIntName), + ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) ) ); } - return NULL; } ScaFuncRes::ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet ) : @@ -195,13 +175,13 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL date_component_getFactory( ScaDateAddIn::ScaDateAddIn() : pDefLocales( NULL ), pResMgr( NULL ), - pFuncDataList( NULL ) + pFuncDataMap( NULL ) { } ScaDateAddIn::~ScaDateAddIn() { - delete pFuncDataList; + delete pFuncDataMap; delete pResMgr; delete[] pDefLocales; } @@ -244,9 +224,17 @@ void ScaDateAddIn::InitData() { delete pResMgr; pResMgr = ResMgr::CreateResMgr("date", LanguageTag(aFuncLoc)); - delete pFuncDataList; + delete pFuncDataMap; - pFuncDataList = pResMgr ? new ScaFuncDataList( *pResMgr ) : NULL; + if ( pResMgr ) + { + pFuncDataMap = new ScaFuncDataMap; + InitScaFuncDataMap( *pFuncDataMap, *pResMgr ); + } + else + { + pFuncDataMap = nullptr; + } if( pDefLocales ) { @@ -335,11 +323,12 @@ OUString SAL_CALL ScaDateAddIn::getDisplayFunctionName( const OUString& aProgram { OUString aRet; - const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); - if( pFData ) + auto fDataIt = pFuncDataMap->find( aProgrammaticName ); + if( fDataIt != pFuncDataMap->end() ) { - aRet = GetDisplFuncStr( pFData->GetUINameID() ); - if( pFData->IsDouble() ) + ScaFuncData& fData = fDataIt->second; + aRet = GetDisplFuncStr( fData.GetUINameID() ); + if( fData.IsDouble() ) aRet += STR_FROM_ANSI( "_ADD" ); } else @@ -355,9 +344,9 @@ OUString SAL_CALL ScaDateAddIn::getFunctionDescription( const OUString& aProgram { OUString aRet; - const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); - if( pFData ) - aRet = GetFuncDescrStr( pFData->GetDescrID(), 1 ); + auto fDataIt = pFuncDataMap->find( aProgrammaticName ); + if( fDataIt != pFuncDataMap->end() ) + aRet = GetFuncDescrStr( fDataIt->second.GetDescrID(), 1 ); return aRet; } @@ -367,12 +356,13 @@ OUString SAL_CALL ScaDateAddIn::getDisplayArgumentName( { OUString aRet; - const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); - if( pFData && (nArgument <= 0xFFFF) ) + auto fDataIt = pFuncDataMap->find( aProgrammaticName ); + if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) ) { - sal_uInt16 nStr = pFData->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); + auto fData = fDataIt->second; + sal_uInt16 nStr = fData.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); if( nStr ) - aRet = GetFuncDescrStr( pFData->GetDescrID(), nStr ); + aRet = GetFuncDescrStr( fData.GetDescrID(), nStr ); else aRet = STR_FROM_ANSI( "internal" ); } @@ -385,12 +375,13 @@ OUString SAL_CALL ScaDateAddIn::getArgumentDescription( { OUString aRet; - const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); - if( pFData && (nArgument <= 0xFFFF) ) + auto fDataIt = pFuncDataMap->find( aProgrammaticName ); + if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) ) { - sal_uInt16 nStr = pFData->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); + auto fData = fDataIt->second; + sal_uInt16 nStr = fData.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); if( nStr ) - aRet = GetFuncDescrStr( pFData->GetDescrID(), nStr + 1 ); + aRet = GetFuncDescrStr( fData.GetDescrID(), nStr + 1 ); else aRet = STR_FROM_ANSI( "for internal use only" ); } @@ -403,10 +394,10 @@ OUString SAL_CALL ScaDateAddIn::getProgrammaticCategoryName( { OUString aRet; - const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); - if( pFData ) + auto fDataIt = pFuncDataMap->find( aProgrammaticName ); + if( fDataIt != pFuncDataMap->end() ) { - switch( pFData->GetCategory() ) + switch( fDataIt->second.GetCategory() ) { case ScaCat_DateTime: aRet = STR_FROM_ANSI( "Date&Time" ); break; case ScaCat_Text: aRet = STR_FROM_ANSI( "Text" ); break; @@ -435,11 +426,11 @@ OUString SAL_CALL ScaDateAddIn::getDisplayCategoryName( uno::Sequence< sheet::LocalizedName > SAL_CALL ScaDateAddIn::getCompatibilityNames( const OUString& aProgrammaticName ) throw( uno::RuntimeException, std::exception ) { - const ScaFuncData* pFData = pFuncDataList->Get( aProgrammaticName ); - if( !pFData ) + auto fDataIt = pFuncDataMap->find( aProgrammaticName ); + if( fDataIt == pFuncDataMap->end() ) return uno::Sequence< sheet::LocalizedName >( 0 ); - const std::vector<OUString>& rStrList = pFData->GetCompNameList(); + const std::vector<OUString>& rStrList = fDataIt->second.GetCompNameList(); sal_uInt32 nCount = rStrList.size(); uno::Sequence< sheet::LocalizedName > aRet( nCount ); diff --git a/scaddins/source/datefunc/datefunc.hxx b/scaddins/source/datefunc/datefunc.hxx index db6e8f1..04031aa 100644 --- a/scaddins/source/datefunc/datefunc.hxx +++ b/scaddins/source/datefunc/datefunc.hxx @@ -24,6 +24,7 @@ #include <string.h> #include <vector> +#include <map> #include <com/sun/star/lang/XServiceName.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -171,7 +172,7 @@ struct ScaFuncDataBase class ScaFuncData { private: - OUString aIntName; // internal name (get***) + OUString aIntName; // internal name (get***) sal_uInt16 nUINameID; // resource ID to UI name sal_uInt16 nDescrID; // leads also to parameter descriptions! sal_uInt16 nCompListID; // resource ID to list of valid names @@ -197,43 +198,9 @@ public: inline const std::vector<OUString>& GetCompNameList() const { return aCompList; } }; +typedef std::map<OUString, ScaFuncData> ScaFuncDataMap; -class ScaFuncDataList : private ScaList -{ - OUString aLastName; - sal_uInt32 nLast; - -public: - ScaFuncDataList( ResMgr& rResMgr ); - virtual ~ScaFuncDataList(); - - using ScaList::Count; - - inline const ScaFuncData* Get( sal_uInt32 nIndex ) const; - const ScaFuncData* Get( const OUString& rProgrammaticName ) const; - inline ScaFuncData* First(); - inline ScaFuncData* Next(); - - using ScaList::Append; - inline void Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); } -}; - - -inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const -{ - return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) ); -} - -inline ScaFuncData* ScaFuncDataList::First() -{ - return static_cast< ScaFuncData* >( ScaList::First() ); -} - -inline ScaFuncData* ScaFuncDataList::Next() -{ - return static_cast< ScaFuncData* >( ScaList::Next() ); -} - +void InitScaFuncDataMap ( ScaFuncDataMap& rMap, ResMgr& rResMgr ); ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance( @@ -253,8 +220,8 @@ class ScaDateAddIn : public ::cppu::WeakImplHelper6< private: ::com::sun::star::lang::Locale aFuncLoc; ::com::sun::star::lang::Locale* pDefLocales; - ResMgr* pResMgr; - ScaFuncDataList* pFuncDataList; + ResMgr* pResMgr; + ScaFuncDataMap* pFuncDataMap; void InitDefLocales(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits