summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorTobias Lippert <drtl@fastmail.fm>2014-03-05 20:06:39 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-03-11 08:54:37 -0500
commit0c17ccc493d0c7a80f37600dae76a09a119bef78 (patch)
tree70fd1963d59bbb8dba95ed4d92053f2c9f3115cb /sd
parente3e1f9f30d80961fd282f9ce765ffb1111201344 (diff)
fdo#30770 - Speed up xslx import
Conflicts: include/svl/style.hxx Change-Id: Ie3d855923c651b6e05c0054c8e30155218279045 Reviewed-on: https://gerrit.libreoffice.org/8485 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/source/core/drawdoc4.cxx1
-rw-r--r--sd/source/core/stlpool.cxx99
2 files changed, 72 insertions, 28 deletions
diff --git a/sd/source/core/drawdoc4.cxx b/sd/source/core/drawdoc4.cxx
index a6f939b7639d..8ebb9250a3b7 100644
--- a/sd/source/core/drawdoc4.cxx
+++ b/sd/source/core/drawdoc4.cxx
@@ -1103,6 +1103,7 @@ void SdDrawDocument::RenameLayoutTemplate(const OUString& rOldLayoutName, const
aReplList.push_back(aReplData);
pSheet->SetName(aSheetName);
+ mxStyleSheetPool.get()->Reindex();
}
pSheet = aIter.Next();
diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx
index 457350afd8b8..6b88b0bc6e75 100644
--- a/sd/source/core/stlpool.cxx
+++ b/sd/source/core/stlpool.cxx
@@ -53,6 +53,7 @@
#include <editeng/adjustitem.hxx>
#include <editeng/numdef.hxx>
#include <svl/itempool.hxx>
+#include <svl/IndexedStyleSheets.hxx>
#include "stlpool.hxx"
#include "sdresid.hxx"
@@ -127,8 +128,6 @@ SdStyleSheetPool::SdStyleSheetPool(SfxItemPool const& _rPool, SdDrawDocument* pD
}
}
-
-
SdStyleSheetPool::~SdStyleSheetPool()
{
DBG_ASSERT( mpDoc == NULL, "sd::SdStyleSheetPool::~SdStyleSheetPool(), dispose me first!" );
@@ -624,41 +623,66 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily
CopySheets(rSourcePool, eFamily, rCreatedSheets, emptyName);
}
+namespace
+{
+
+struct HasFamilyPredicate : svl::StyleSheetPredicate
+{
+ HasFamilyPredicate(SfxStyleFamily eFamily)
+ : meFamily(eFamily) {;}
+
+ bool Check(const SfxStyleSheetBase& sheet)
+ {
+ return sheet.GetFamily() == meFamily;
+ }
+ SfxStyleFamily meFamily;
+};
+
+}
+
void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets, OUString& rRenameSuffix)
{
OUString aHelpFile;
- sal_uInt32 nCount = rSourcePool.aStyles.size();
-
std::vector< std::pair< rtl::Reference< SfxStyleSheetBase >, OUString > > aNewStyles;
std::vector< std::pair< OUString, OUString > > aRenamedList;
- for (sal_uInt32 n = 0; n < nCount; n++)
+ // find all style sheets of the source pool which have the same family
+ HasFamilyPredicate aHasFamilyPredicate(eFamily);
+ std::vector<unsigned> aSheetsWithFamily = rSourcePool.GetIndexedStyleSheets().FindPositionsByPredicate(aHasFamilyPredicate);
+
+ for (std::vector<unsigned>::const_iterator it = aSheetsWithFamily.begin();
+ it != aSheetsWithFamily.end(); ++it )
{
- rtl::Reference< SfxStyleSheetBase > xSheet( rSourcePool.aStyles[sal::static_int_cast<sal_uInt16>(n)] );
+ rtl::Reference< SfxStyleSheetBase > xSheet = GetStyleSheetByPositionInIndex( *it );
+ rtl::OUString aName( xSheet->GetName() );
- if( xSheet->GetFamily() == eFamily )
+ // now check whether we already have a sheet with the same name
+ std::vector<unsigned> aSheetsWithName = GetIndexedStyleSheets().FindPositionsByName(aName);
+ bool bAddToList = false;
+ if (!aSheetsWithName.empty() && !rRenameSuffix.isEmpty())
{
- bool bAddToList = false;
- OUString aName( xSheet->GetName() );
- SfxStyleSheetBase* pExistingSheet = Find(aName, eFamily);
- if( pExistingSheet && !rRenameSuffix.isEmpty() )
+ // if we have a rename suffix, try to find a new name
+ SfxStyleSheetBase* pExistingSheet = GetStyleSheetByPositionInIndex(aSheetsWithName.front()).get();
+ sal_Int32 nHash = xSheet->GetItemSet().getHash();
+ if( pExistingSheet->GetItemSet().getHash() != nHash )
{
- sal_Int32 nHash = xSheet->GetItemSet().getHash();
- if( pExistingSheet->GetItemSet().getHash() != nHash )
+ // we have found a sheet with the same name, but different contents. Try to find a new name.
+ // If we already have a sheet with the new name, and it is equal to the one in the source pool,
+ // do nothing.
+ OUString aTmpName = aName + rRenameSuffix;
+ sal_Int32 nSuffix = 1;
+ do
{
- OUString aTmpName = aName + rRenameSuffix;
- sal_Int32 nSuffix = 1;
- do
- {
- aTmpName = aName + rRenameSuffix + OUString::number(nSuffix);
- pExistingSheet = Find(aTmpName, eFamily);
- nSuffix++;
- } while( pExistingSheet && pExistingSheet->GetItemSet().getHash() != nHash );
- aName = aTmpName;
- bAddToList = true;
- }
+ aTmpName = aName + rRenameSuffix + OUString::number(nSuffix);
+ pExistingSheet = Find(aTmpName, eFamily);
+ nSuffix++;
+ } while( pExistingSheet && pExistingSheet->GetItemSet().getHash() != nHash );
+ aName = aTmpName;
+ bAddToList = true;
}
+
+ // we do not already have a sheet with the same name and contents. Create a new one.
if ( !pExistingSheet )
{
rtl::Reference< SfxStyleSheetBase > xNewSheet( &Make( aName, eFamily ) );
@@ -701,6 +725,8 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily
DBG_ASSERT( rSourcePool.Find( (*aIter).second, eFamily ), "StyleSheet has invalid parent: Family mismatch" );
(*aIter).first->SetParent( (*aIter).second );
}
+ // we have changed names of style sheets. Trigger reindexing.
+ Reindex();
}
@@ -902,15 +928,30 @@ void SdStyleSheetPool::CreatePseudosIfNecessary()
|*
\************************************************************************/
+namespace
+{
+struct StyleSheetIsUserDefinedPredicate : svl::StyleSheetPredicate
+{
+ StyleSheetIsUserDefinedPredicate()
+ {;}
+
+ bool Check(const SfxStyleSheetBase& sheet)
+ {
+ return sheet.IsUserDefined();
+ }
+};
+}
+
void SdStyleSheetPool::UpdateStdNames()
{
OUString aHelpFile;
- sal_uInt32 nCount = aStyles.size();
+ StyleSheetIsUserDefinedPredicate aPredicate;
std::vector<SfxStyleSheetBase*> aEraseList;
-
- for( sal_uInt32 n=0; n < nCount; n++ )
+ std::vector<unsigned> aUserDefinedStyles = GetIndexedStyleSheets().FindPositionsByPredicate(aPredicate);
+ for (std::vector<unsigned>::const_iterator it = aUserDefinedStyles.begin();
+ it != aUserDefinedStyles.end(); ++it)
{
- SfxStyleSheetBase* pStyle = aStyles[ n ].get();
+ SfxStyleSheetBase* pStyle = GetStyleSheetByPositionInIndex(*it).get();
if( !pStyle->IsUserDefined() )
{
@@ -991,6 +1032,7 @@ void SdStyleSheetPool::UpdateStdNames()
// Sheet does exist: old sheet has to be removed
aEraseList.push_back( pStyle );
}
+ Reindex();
}
}
}
@@ -999,6 +1041,7 @@ void SdStyleSheetPool::UpdateStdNames()
// styles that could not be renamed, must be removed
for ( size_t i = 0, n = aEraseList.size(); i < n; ++i )
Remove( aEraseList[ i ] );
+ Reindex();
}
// Set new SvxNumBulletItem for the respective style sheet