diff options
author | Ian <ian.gilham@gmail.com> | 2015-08-11 14:01:05 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2015-08-12 11:11:37 +0000 |
commit | 2e23b6b9fc31de8177d72028f4d9441c76015903 (patch) | |
tree | 7f9afd68a73d0f487942e217b8209aa9381ea32e /scaddins | |
parent | a5cebd1bfc15eed5cc2018a88a7b0cd5a841f6bc (diff) |
tdf#90222: Removed ScaList from pricing scaddin
Removed the ScaList type.
Migrated the ScaFuncDataList to a vector and changed lookup to
std::find_if with a functor. This reduces memory use slightly and makes
the use of the lookup result a little simpler.
Change-Id: I4e5f4d27107512a7c53935f123d5e7e8aca625ee
Reviewed-on: https://gerrit.libreoffice.org/17652
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'scaddins')
-rw-r--r-- | scaddins/source/pricing/pricing.cxx | 99 | ||||
-rw-r--r-- | scaddins/source/pricing/pricing.hxx | 58 |
2 files changed, 47 insertions, 110 deletions
diff --git a/scaddins/source/pricing/pricing.cxx b/scaddins/source/pricing/pricing.cxx index 712a878a41ef..31477074ee03 100644 --- a/scaddins/source/pricing/pricing.cxx +++ b/scaddins/source/pricing/pricing.cxx @@ -29,6 +29,7 @@ #include <cppuhelper/factory.hxx> #include <cppuhelper/supportsservice.hxx> #include <iostream> +#include <algorithm> #include <osl/diagnose.h> #include <rtl/math.hxx> #include <rtl/ustrbuf.hxx> @@ -45,33 +46,6 @@ using namespace sca::pricing; #define STR_FROM_ANSI( s ) OUString( s, strlen( s ), RTL_TEXTENCODING_MS_1252 ) -const sal_uInt32 ScaList::nStartSize = 16; -const sal_uInt32 ScaList::nIncrSize = 16; - -ScaList::ScaList() : - pData( new void*[ nStartSize ] ), - nSize( nStartSize ), - nCount( 0 ), - nCurr( 0 ) -{ -} - -ScaList::~ScaList() -{ - delete[] pData; -} - -void ScaList::_Grow() -{ - nSize += nIncrSize; - - void** pNewData = new void*[ nSize ]; - memcpy( pNewData, pData, nCount * sizeof( void* ) ); - - delete[] pData; - pData = pNewData; -} - ScaResId::ScaResId( sal_uInt16 nId, ResMgr& rResMgr ) : ResId( nId, rResMgr ) { @@ -122,14 +96,10 @@ sal_uInt16 ScaFuncData::GetStrIndex( sal_uInt16 nParam ) const return (nParam > nParamCount) ? (nParamCount * 2) : (nParam * 2); } -void sca::pricing::InitScaFuncDataMap( ScaFuncDataMap& rMap, ResMgr& rResMgr ) +void sca::pricing::InitScaFuncDataList( ScaFuncDataList& rList, ResMgr& rResMgr ) { for( sal_uInt16 nIndex = 0; nIndex < SAL_N_ELEMENTS(pFuncDataArr); nIndex++ ) - { - rMap.insert( std::make_pair( - OUString::createFromAscii(pFuncDataArr[ nIndex ].pIntName), - ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) ) ); - } + rList.push_back( ScaFuncData( pFuncDataArr[ nIndex ], rResMgr ) ) ; } ScaFuncRes::ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet ) : @@ -178,13 +148,13 @@ SAL_DLLPUBLIC_EXPORT void * SAL_CALL pricing_component_getFactory( ScaPricingAddIn::ScaPricingAddIn() : pDefLocales( NULL ), pResMgr( NULL ), - pFuncDataMap( NULL ) + pFuncDataList( NULL ) { } ScaPricingAddIn::~ScaPricingAddIn() { - delete pFuncDataMap; + delete pFuncDataList; delete pResMgr; delete[] pDefLocales; } @@ -227,16 +197,16 @@ void ScaPricingAddIn::InitData() { delete pResMgr; pResMgr = ResMgr::CreateResMgr("pricing", LanguageTag( aFuncLoc) ); - delete pFuncDataMap; + delete pFuncDataList; if(pResMgr) { - pFuncDataMap = new ScaFuncDataMap; - InitScaFuncDataMap( *pFuncDataMap, *pResMgr ); + pFuncDataList = new ScaFuncDataList; + InitScaFuncDataList( *pFuncDataList, *pResMgr ); } else { - pFuncDataMap = nullptr; + pFuncDataList = nullptr; } if( pDefLocales ) @@ -328,12 +298,12 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayFunctionName( const OUString& aProg { OUString aRet; - auto fDataIt = pFuncDataMap->find( aProgrammaticName ); - if(fDataIt != pFuncDataMap->end() ) + auto fDataIt = std::find_if(pFuncDataList->begin(), pFuncDataList->end(), + FindScaFuncData( aProgrammaticName ) ); + if(fDataIt != pFuncDataList->end() ) { - auto data = fDataIt->second; - aRet = GetDisplFuncStr( data.GetUINameID() ); - if( data.IsDouble() ) + aRet = GetDisplFuncStr( fDataIt->GetUINameID() ); + if( fDataIt->IsDouble() ) aRet += STR_FROM_ANSI( "_ADD" ); } else @@ -349,9 +319,10 @@ OUString SAL_CALL ScaPricingAddIn::getFunctionDescription( const OUString& aProg { OUString aRet; - auto fDataIt = pFuncDataMap->find( aProgrammaticName ); - if( fDataIt != pFuncDataMap->end() ) - aRet = GetFuncDescrStr( fDataIt->second.GetDescrID(), 1 ); + auto fDataIt = std::find_if( pFuncDataList->begin(), pFuncDataList->end(), + FindScaFuncData( aProgrammaticName ) ); + if( fDataIt != pFuncDataList->end() ) + aRet = GetFuncDescrStr( fDataIt->GetDescrID(), 1 ); return aRet; } @@ -361,13 +332,13 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayArgumentName( { OUString aRet; - auto fDataIt = pFuncDataMap->find( aProgrammaticName ); - if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) ) + auto fDataIt = std::find_if( pFuncDataList->begin(), pFuncDataList->end(), + FindScaFuncData( aProgrammaticName ) ); + if( fDataIt != pFuncDataList->end() && (nArgument <= 0xFFFF) ) { - auto data = fDataIt->second; - sal_uInt16 nStr = data.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); + sal_uInt16 nStr = fDataIt->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); if( nStr ) - aRet = GetFuncDescrStr( data.GetDescrID(), nStr ); + aRet = GetFuncDescrStr( fDataIt->GetDescrID(), nStr ); else aRet = STR_FROM_ANSI( "internal" ); } @@ -380,13 +351,13 @@ OUString SAL_CALL ScaPricingAddIn::getArgumentDescription( { OUString aRet; - auto fDataIt = pFuncDataMap->find( aProgrammaticName ); - if( fDataIt != pFuncDataMap->end() && (nArgument <= 0xFFFF) ) + auto fDataIt = std::find_if( pFuncDataList->begin(), pFuncDataList->end(), + FindScaFuncData( aProgrammaticName ) ); + if( fDataIt != pFuncDataList->end() && (nArgument <= 0xFFFF) ) { - auto data = fDataIt->second; - sal_uInt16 nStr = data.GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); + sal_uInt16 nStr = fDataIt->GetStrIndex( static_cast< sal_uInt16 >( nArgument ) ); if( nStr ) - aRet = GetFuncDescrStr( data.GetDescrID(), nStr + 1 ); + aRet = GetFuncDescrStr( fDataIt->GetDescrID(), nStr + 1 ); else aRet = STR_FROM_ANSI( "for internal use only" ); } @@ -399,10 +370,11 @@ OUString SAL_CALL ScaPricingAddIn::getProgrammaticCategoryName( { OUString aRet; - auto fDataIt = pFuncDataMap->find( aProgrammaticName ); - if( fDataIt != pFuncDataMap->end() ) + auto fDataIt = std::find_if( pFuncDataList->begin(), pFuncDataList->end(), + FindScaFuncData( aProgrammaticName ) ); + if( fDataIt != pFuncDataList->end() ) { - switch( fDataIt->second.GetCategory() ) + switch( fDataIt->GetCategory() ) { case ScaCat_DateTime: aRet = STR_FROM_ANSI( "Date&Time" ); break; case ScaCat_Text: aRet = STR_FROM_ANSI( "Text" ); break; @@ -431,11 +403,12 @@ OUString SAL_CALL ScaPricingAddIn::getDisplayCategoryName( uno::Sequence< sheet::LocalizedName > SAL_CALL ScaPricingAddIn::getCompatibilityNames( const OUString& aProgrammaticName ) throw( uno::RuntimeException, std::exception ) { - auto fDataIt = pFuncDataMap->find( aProgrammaticName ); - if( fDataIt == pFuncDataMap->end() ) + auto fDataIt = std::find_if( pFuncDataList->begin(), pFuncDataList->end(), + FindScaFuncData( aProgrammaticName ) ); + if( fDataIt == pFuncDataList->end() ) return uno::Sequence< sheet::LocalizedName >( 0 ); - const std::vector<OUString>& rStrList = fDataIt->second.GetCompNameList(); + const std::vector<OUString>& rStrList = fDataIt->GetCompNameList(); sal_uInt32 nCount = rStrList.size(); uno::Sequence< sheet::LocalizedName > aRet( nCount ); diff --git a/scaddins/source/pricing/pricing.hxx b/scaddins/source/pricing/pricing.hxx index 4cb713346cc2..d66f918b1d0f 100644 --- a/scaddins/source/pricing/pricing.hxx +++ b/scaddins/source/pricing/pricing.hxx @@ -30,7 +30,6 @@ #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> @@ -49,49 +48,6 @@ namespace sca { namespace pricing { -class ScaList -{ -private: - static const sal_uInt32 nStartSize; - static const sal_uInt32 nIncrSize; - - void** pData; // pointer array - sal_uInt32 nSize; // array size - sal_uInt32 nCount; // next index to be inserted at - sal_uInt32 nCurr; // current pos for iterations - - void _Grow(); - inline void Grow(); - -public: - ScaList(); - virtual ~ScaList(); - - inline sal_uInt32 Count() const { return nCount; } - - inline const void* GetObject( sal_uInt32 nIndex ) const - { return (nIndex < nCount) ? pData[ nIndex ] : NULL; } - - inline void* First() { return nCount ? pData[ nCurr = 0 ] : NULL; } - inline void* Next() { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; } - - inline void Append( void* pNew ); -}; - - -inline void ScaList::Grow() -{ - if( nCount >= nSize ) - _Grow(); -} - -inline void ScaList::Append( void* pNew ) -{ - Grow(); - pData[ nCount++ ] = pNew; -} - - class ScaResId : public ResId { public: @@ -211,9 +167,17 @@ public: }; -typedef std::map<OUString, ScaFuncData> ScaFuncDataMap; +typedef std::vector<ScaFuncData> ScaFuncDataList; + +void InitScaFuncDataList ( ScaFuncDataList& rMap, ResMgr& rResMgr ); -void InitScaFuncDataMap ( ScaFuncDataMap& rMap, ResMgr& rResMgr ); +// Predicate for use with std::find_if +struct FindScaFuncData +{ + const OUString& m_rId; + explicit FindScaFuncData( const OUString& rId ) : m_rId(rId) {} + bool operator() ( ScaFuncData& rCandidate ) const { return rCandidate.Is(m_rId); } +}; } // namespace pricing } // namespace sca @@ -238,7 +202,7 @@ private: css::lang::Locale aFuncLoc; css::lang::Locale* pDefLocales; ResMgr* pResMgr; - sca::pricing::ScaFuncDataMap* pFuncDataMap; + sca::pricing::ScaFuncDataList* pFuncDataList; void InitDefLocales(); |