From fad417fe49d9da0fdef7447521a4bcd962d5c9eb Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Mon, 24 Sep 2012 21:19:09 -0400 Subject: Prevent so many copying of vector instances. Change-Id: I2d74fe70411fb1a12387458d170a4a6b603755a3 --- chart2/source/inc/ExplicitCategoriesProvider.hxx | 2 +- chart2/source/tools/ExplicitCategoriesProvider.cxx | 9 +++-- chart2/source/view/axes/VCartesianAxis.cxx | 39 ++++++++++++++-------- 3 files changed, 30 insertions(+), 20 deletions(-) (limited to 'chart2') diff --git a/chart2/source/inc/ExplicitCategoriesProvider.hxx b/chart2/source/inc/ExplicitCategoriesProvider.hxx index b83052b51ed8..d96ef67253a1 100644 --- a/chart2/source/inc/ExplicitCategoriesProvider.hxx +++ b/chart2/source/inc/ExplicitCategoriesProvider.hxx @@ -84,7 +84,7 @@ public: ::com::sun::star::chart2::data::XDataSequence > getOriginalCategories(); ::com::sun::star::uno::Sequence< ::rtl::OUString > getSimpleCategories(); - ::std::vector< ComplexCategory > getCategoriesByLevel( sal_Int32 nLevel ); + const std::vector* getCategoriesByLevel( sal_Int32 nLevel ); static ::rtl::OUString getCategoryByIndex( const ::com::sun::star::uno::Reference< diff --git a/chart2/source/tools/ExplicitCategoriesProvider.cxx b/chart2/source/tools/ExplicitCategoriesProvider.cxx index 9cc82b6f383a..e3d800f1b1f8 100644 --- a/chart2/source/tools/ExplicitCategoriesProvider.cxx +++ b/chart2/source/tools/ExplicitCategoriesProvider.cxx @@ -556,14 +556,13 @@ Sequence< ::rtl::OUString > ExplicitCategoriesProvider::getSimpleCategories() return m_aExplicitCategories; } -std::vector< ComplexCategory > ExplicitCategoriesProvider::getCategoriesByLevel( sal_Int32 nLevel ) +const std::vector* ExplicitCategoriesProvider::getCategoriesByLevel( sal_Int32 nLevel ) { - std::vector< ComplexCategory > aRet; init(); sal_Int32 nMaxIndex = m_aComplexCats.size()-1; - if( nLevel >= 0 && nLevel <= nMaxIndex ) - aRet = m_aComplexCats[nMaxIndex-nLevel]; - return aRet; + if (nLevel >= 0 && nLevel <= nMaxIndex) + return &m_aComplexCats[nMaxIndex-nLevel]; + return NULL; } OUString ExplicitCategoriesProvider::getCategoryByIndex( diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index 6c0dd0424090..f394ef828c24 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -463,10 +463,16 @@ void VCartesianAxis::createAllTickInfosFromComplexCategories( ::std::vector< ::s for( ; nLevel aTickInfoVector; - std::vector< ComplexCategory > aComplexCategories( m_aAxisProperties.m_pExplicitCategoriesProvider->getCategoriesByLevel( nLevel ) ); + const std::vector* pComplexCategories = + m_aAxisProperties.m_pExplicitCategoriesProvider->getCategoriesByLevel(nLevel); + + if (!pComplexCategories) + continue; + sal_Int32 nCatIndex = 0; - std::vector< ComplexCategory >::const_iterator aIt(aComplexCategories.begin()); - std::vector< ComplexCategory >::const_iterator aEnd(aComplexCategories.end()); + std::vector::const_iterator aIt = pComplexCategories->begin(); + std::vector::const_iterator aEnd = pComplexCategories->end(); + for(;aIt!=aEnd;++aIt) { TickInfo aTickInfo(0); @@ -497,20 +503,25 @@ void VCartesianAxis::createAllTickInfosFromComplexCategories( ::std::vector< ::s for( ; nLevel aTickInfoVector; - std::vector< ComplexCategory > aComplexCategories( m_aAxisProperties.m_pExplicitCategoriesProvider->getCategoriesByLevel( nLevel ) ); + const std::vector* pComplexCategories = + m_aAxisProperties.m_pExplicitCategoriesProvider->getCategoriesByLevel(nLevel); sal_Int32 nCatIndex = 0; - std::vector< ComplexCategory >::const_iterator aIt(aComplexCategories.begin()); - std::vector< ComplexCategory >::const_iterator aEnd(aComplexCategories.end()); - for(;aIt!=aEnd;++aIt) + if (pComplexCategories) { - TickInfo aTickInfo(0); - ComplexCategory aCat(*aIt); - aTickInfo.fScaledTickValue = nCatIndex + 1.0; - aTickInfoVector.push_back(aTickInfo); - nCatIndex += aCat.Count; - if( nCatIndex + 1.0 > m_aScale.Maximum ) - break; + std::vector::const_iterator aIt = pComplexCategories->begin(); + std::vector::const_iterator aEnd = pComplexCategories->end(); + for(;aIt!=aEnd;++aIt) + { + TickInfo aTickInfo(0); + ComplexCategory aCat(*aIt); + aTickInfo.fScaledTickValue = nCatIndex + 1.0; + aTickInfoVector.push_back(aTickInfo); + nCatIndex += aCat.Count; + if( nCatIndex + 1.0 > m_aScale.Maximum ) + break; + } } + //fill up with single ticks until maximum scale while( nCatIndex + 1.0 < m_aScale.Maximum ) { -- cgit