Kaydet (Commit) 0f1ccf83 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Andras Timar

tdf#62095 fix O(n^2) algorithm in opening pathological file

with tons of missing styles

Change-Id: I93c41f1e461a6e148e9f4c1dd84a598ca0090b54
üst c227e071
...@@ -2758,7 +2758,7 @@ void CellStyleBuffer::finalizeImport() ...@@ -2758,7 +2758,7 @@ void CellStyleBuffer::finalizeImport()
/* If a builtin style entry already exists, and we do not reserve all /* If a builtin style entry already exists, and we do not reserve all
existing styles, we just stick with the last definition and ignore existing styles, we just stick with the last definition and ignore
the preceding ones. */ the preceding ones. */
if( bReserveAll && (aCellStyles.count( aStyleName ) > 0) ) if( bReserveAll && (aCellStyles.find( aStyleName ) != aCellStyles.end()) )
aConflictNameStyles.push_back( *aIt ); aConflictNameStyles.push_back( *aIt );
else else
aCellStyles[ aStyleName ] = *aIt; aCellStyles[ aStyleName ] = *aIt;
...@@ -2773,7 +2773,7 @@ void CellStyleBuffer::finalizeImport() ...@@ -2773,7 +2773,7 @@ void CellStyleBuffer::finalizeImport()
// #i1624# #i1768# ignore unnamed user styles // #i1624# #i1768# ignore unnamed user styles
if( aStyleName.getLength() > 0 ) if( aStyleName.getLength() > 0 )
{ {
if( aCellStyles.count( aStyleName ) > 0 ) if( aCellStyles.find( aStyleName ) != aCellStyles.end() )
aConflictNameStyles.push_back( *aIt ); aConflictNameStyles.push_back( *aIt );
else else
aCellStyles[ aStyleName ] = *aIt; aCellStyles[ aStyleName ] = *aIt;
...@@ -2781,17 +2781,18 @@ void CellStyleBuffer::finalizeImport() ...@@ -2781,17 +2781,18 @@ void CellStyleBuffer::finalizeImport()
} }
// find unused names for all styles with conflicting names // 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 ) for( CellStyleVector::iterator aIt = aConflictNameStyles.begin(), aEnd = aConflictNameStyles.end(); aIt != aEnd; ++aIt )
{ {
const CellStyleModel& rModel = (*aIt)->getModel(); const CellStyleModel& rModel = (*aIt)->getModel();
OUString aStyleName = lclCreateStyleName( rModel ); OUString aStyleName = lclCreateStyleName( rModel );
OUString aUnusedName; OUString aUnusedName;
sal_Int32 nIndex = 0;
do do
{ {
aUnusedName = OUStringBuffer( aStyleName ).append( ' ' ).append( ++nIndex ).makeStringAndClear(); aUnusedName = OUStringBuffer( aStyleName ).append( ' ' ).append( ++nIndex ).makeStringAndClear();
} }
while( aCellStyles.count( aUnusedName ) > 0 ); while( aCellStyles.find( aUnusedName ) != aCellStyles.end() );
aCellStyles[ aUnusedName ] = *aIt; aCellStyles[ aUnusedName ] = *aIt;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment