sw/source/core/txtnode/thints.cxx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
New commits: commit b779b948cc46461b9c7aaa0a01d719879dfe65e5 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed May 3 13:47:57 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed May 3 19:12:27 2023 +0200 tdf#136991 speed up large rtf load We can limit the search when scanning the portion map, based on what the previous search returned. Reduces load time by 10%. Change-Id: I46ef6e80b4ef100318d911a636e28b166b053779 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151321 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx index 871304abeaa8..229df8e3cda9 100644 --- a/sw/source/core/txtnode/thints.cxx +++ b/sw/source/core/txtnode/thints.cxx @@ -2783,10 +2783,10 @@ bool SwpHints::MergePortions( SwTextNode& rNode ) } // we add data strictly in-order, so we can binary-search the vector - auto equal_range = [&aPortionMap](int i) + auto equal_range = [](PortionMap::const_iterator startIt, PortionMap::const_iterator endIt, int i) { Portion key { nullptr, i, false }; - return std::equal_range(aPortionMap.begin(), aPortionMap.end(), key, + return std::equal_range(startIt, endIt, key, [] (const Portion& lhs, const Portion& rhs) -> bool { return lhs.nKey < rhs.nKey; @@ -2798,10 +2798,13 @@ bool SwpHints::MergePortions( SwTextNode& rNode ) // IgnoreEnd at first / last portion int i = 0; int j = i + 1; + // Store these outside the loop, because we limit the search area on subsequent searches. + std::pair< PortionMap::const_iterator, PortionMap::const_iterator > aRange1 { aPortionMap.begin(), aPortionMap.begin() + aPortionMap.size() }; while ( i <= nKey ) { - std::pair< PortionMap::const_iterator, PortionMap::const_iterator > aRange1 = equal_range( i ); - std::pair< PortionMap::const_iterator, PortionMap::const_iterator > aRange2 = equal_range( j ); + aRange1 = equal_range( aRange1.first, aPortionMap.begin() + aPortionMap.size(), i ); + std::pair< PortionMap::const_iterator, PortionMap::const_iterator > aRange2 + = equal_range( aRange1.first, aPortionMap.begin() + aPortionMap.size(), j ); MergeResult eMerge = lcl_Compare_Attributes(i, j, aRange1, aRange2, RsidOnlyAutoFormatFlagMap); @@ -2827,7 +2830,7 @@ bool SwpHints::MergePortions( SwTextNode& rNode ) ++j; // change all attributes with key i - aRange1 = equal_range( i ); + aRange1 = equal_range( aRange1.first, aPortionMap.begin() + aPortionMap.size(), i ); for ( auto aIter1 = aRange1.first; aIter1 != aRange1.second; ++aIter1 ) { SwTextAttr *const p1 = aIter1->pTextAttr;