summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-03-01 14:53:46 +0100
committerLuboš Luňák <l.lunak@collabora.com>2022-03-23 09:09:06 +0100
commit3f99ff783cb147c5f853230315a92cfb38eb14b9 (patch)
tree484ad9acc7fe26bf9db191f24f4132b2c5d96d09
parent0a99967b60845f8f9acaf6e7a112e88d05fb3ede (diff)
try to avoid using map when searching most used item (tdf#95346)
The last item is usually going to be the most common, so first check that. Change-Id: Ibad8b6bb9a829a96691c10b780b8e52610475126 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130794 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r--sc/source/filter/excel/xetable.cxx36
1 files changed, 21 insertions, 15 deletions
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index 75567ccd480d..5b366aef34ff 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1985,29 +1985,35 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, size_t nStartColAll
size_t nStartAllDefault = findFirstAllSameUntilEnd( aXFIndexes, EXC_XF_DEFAULTCELL, nStartSearchAllDefault);
// find most used XF index in the row
- std::unordered_map< sal_uInt16, size_t > aIndexMap;
sal_uInt16 nRowXFIndex = EXC_XF_DEFAULTCELL;
const size_t nHalfIndexes = aXFIndexes.size() / 2;
if( nStartAllDefault > nHalfIndexes ) // Otherwise most are EXC_XF_DEFAULTCELL.
{
- size_t nMaxXFCount = 0;
- for( const auto& rXFIndex : aXFIndexes )
+ // Very likely the most common one is going to be the last one.
+ nRowXFIndex = aXFIndexes.back();
+ size_t nStartLastSame = findFirstAllSameUntilEnd( aXFIndexes, nRowXFIndex );
+ if( nStartLastSame > nHalfIndexes ) // No, find out the most used one by counting.
{
- if( rXFIndex != EXC_XF_NOTFOUND )
+ std::unordered_map< sal_uInt16, size_t > aIndexMap;
+ size_t nMaxXFCount = 0;
+ for( const auto& rXFIndex : aXFIndexes )
{
- size_t& rnCount = aIndexMap[ rXFIndex ];
- ++rnCount;
- if( rnCount > nMaxXFCount )
+ if( rXFIndex != EXC_XF_NOTFOUND )
{
- nRowXFIndex = rXFIndex;
- nMaxXFCount = rnCount;
- if (nMaxXFCount > nHalfIndexes)
+ size_t& rnCount = aIndexMap[ rXFIndex ];
+ ++rnCount;
+ if( rnCount > nMaxXFCount )
{
- // No other XF index can have a greater usage count, we
- // don't need to loop through the remaining cells.
- // Specifically for the tail of unused default
- // cells/columns this makes a difference.
- break; // for
+ nRowXFIndex = rXFIndex;
+ nMaxXFCount = rnCount;
+ if (nMaxXFCount > nHalfIndexes)
+ {
+ // No other XF index can have a greater usage count, we
+ // don't need to loop through the remaining cells.
+ // Specifically for the tail of unused default
+ // cells/columns this makes a difference.
+ break; // for
+ }
}
}
}