summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-06-12 14:37:34 +0200
committerNoel Grandin <noel@peralex.com>2015-06-12 14:37:46 +0200
commitf6a9b58bc72c1918f965043035dd1c04a0772820 (patch)
tree513f40dfcb6eacc8ea8edf7b6e4e3a3a3a93c5d2
parent7750dfccbdafe0b487d4e3f52a672c57db1de24b (diff)
tdf#62095 fix O(n^2) algorithm in opening pathological file
with tons of missing styles Change-Id: I93c41f1e461a6e148e9f4c1dd84a598ca0090b54
-rw-r--r--sc/source/filter/oox/stylesbuffer.cxx9
1 files changed, 5 insertions, 4 deletions
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index 598ea497e311..bf63786e9725 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2758,7 +2758,7 @@ void CellStyleBuffer::finalizeImport()
/* If a builtin style entry already exists, and we do not reserve all
existing styles, we just stick with the last definition and ignore
the preceding ones. */
- if( bReserveAll && (aCellStyles.count( aStyleName ) > 0) )
+ if( bReserveAll && (aCellStyles.find( aStyleName ) != aCellStyles.end()) )
aConflictNameStyles.push_back( *aIt );
else
aCellStyles[ aStyleName ] = *aIt;
@@ -2773,7 +2773,7 @@ void CellStyleBuffer::finalizeImport()
// #i1624# #i1768# ignore unnamed user styles
if( aStyleName.getLength() > 0 )
{
- if( aCellStyles.count( aStyleName ) > 0 )
+ if( aCellStyles.find( aStyleName ) != aCellStyles.end() )
aConflictNameStyles.push_back( *aIt );
else
aCellStyles[ aStyleName ] = *aIt;
@@ -2781,17 +2781,18 @@ void CellStyleBuffer::finalizeImport()
}
// find unused names for all styles with conflicting names
+ // having the index counter outside the loop prevents performance problems with opening some pathological documents (tdf#62095)
+ sal_Int32 nIndex = 0;
for( CellStyleVector::iterator aIt = aConflictNameStyles.begin(), aEnd = aConflictNameStyles.end(); aIt != aEnd; ++aIt )
{
const CellStyleModel& rModel = (*aIt)->getModel();
OUString aStyleName = lclCreateStyleName( rModel );
OUString aUnusedName;
- sal_Int32 nIndex = 0;
do
{
aUnusedName = OUStringBuffer( aStyleName ).append( ' ' ).append( ++nIndex ).makeStringAndClear();
}
- while( aCellStyles.count( aUnusedName ) > 0 );
+ while( aCellStyles.find( aUnusedName ) != aCellStyles.end() );
aCellStyles[ aUnusedName ] = *aIt;
}