From 5b51ca963903dd1fb74e8314fa556b510d5f7ee9 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 11 Sep 2020 09:13:26 +0200 Subject: optimisation: use o3tl::sorted_vector in XMLPropertyStates_Impl Change-Id: I9774e0d3f29decedd910fafe3c3174bab930f521 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102438 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmloff/source/style/xmlexppr.cxx | 49 ++++++++++------------------------------ 1 file changed, 12 insertions(+), 37 deletions(-) (limited to 'xmloff') diff --git a/xmloff/source/style/xmlexppr.cxx b/xmloff/source/style/xmlexppr.cxx index 92ba262a1921..b65669aed3c3 100644 --- a/xmloff/source/style/xmlexppr.cxx +++ b/xmloff/source/style/xmlexppr.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -91,62 +92,36 @@ XMLPropTokens_Impl const aPropTokens[MAX_PROP_TYPES] = // if a state is available. // After that I call the method 'ContextFilter'. -typedef std::list XMLPropertyStateList_Impl; - +struct ComparePropertyState +{ + bool operator()(XMLPropertyState const& lhs, XMLPropertyState const& rhs) + { + return lhs.mnIndex < rhs.mnIndex; + } +}; class XMLPropertyStates_Impl { - XMLPropertyStateList_Impl aPropStates; - XMLPropertyStateList_Impl::iterator aLastItr; - sal_uInt32 nCount; + o3tl::sorted_vector aPropStates; public: XMLPropertyStates_Impl(); void AddPropertyState(const XMLPropertyState& rPropState); void FillPropertyStateVector(std::vector& rVector); }; -XMLPropertyStates_Impl::XMLPropertyStates_Impl() : - aPropStates(), - nCount(0) +XMLPropertyStates_Impl::XMLPropertyStates_Impl() { - aLastItr = aPropStates.begin(); } void XMLPropertyStates_Impl::AddPropertyState( const XMLPropertyState& rPropState) { - XMLPropertyStateList_Impl::iterator aItr = aPropStates.begin(); - bool bInserted(false); - if (nCount) - { - if (aLastItr->mnIndex < rPropState.mnIndex) - aItr = ++aLastItr; - } - do - { - // TODO: one path required only - if (aItr == aPropStates.end()) - { - aLastItr = aPropStates.insert(aPropStates.end(), rPropState); - bInserted = true; - nCount++; - } - else if (aItr->mnIndex > rPropState.mnIndex) - { - aLastItr = aPropStates.insert(aItr, rPropState); - bInserted = true; - nCount++; - } - } - while(!bInserted && (aItr++ != aPropStates.end())); + aPropStates.insert(rPropState); } void XMLPropertyStates_Impl::FillPropertyStateVector( std::vector& rVector) { - if (nCount) - { - rVector.insert( rVector.begin(), aPropStates.begin(), aPropStates.end() ); - } + rVector.insert( rVector.begin(), aPropStates.begin(), aPropStates.end() ); } class FilterPropertyInfo_Impl -- cgit