Kaydet (Commit) e89ab73f authored tarafından Matthias Hofmann's avatar Matthias Hofmann Kaydeden (comit) Thorsten Behrens

remove ShapeList::getNextShape(SdrObject* pObj)

The getNextShape(pObj) method is just used for iterating over the complete
ShapeList. But the complexity for this operation is exponential.
When using getNextShape() iterating over the list have linear complexity.
In short: it is much faster.

Change-Id: I3896af2247f348153d62f2bcdd207c5a75239689
Reviewed-on: https://gerrit.libreoffice.org/4132Reviewed-by: 's avatarThorsten Behrens <tbehrens@suse.com>
Tested-by: 's avatarThorsten Behrens <tbehrens@suse.com>
üst 8ea041fe
...@@ -48,16 +48,12 @@ namespace sd ...@@ -48,16 +48,12 @@ namespace sd
/** @return true if given shape is part of this list */ /** @return true if given shape is part of this list */
bool hasShape( SdrObject& rObject ) const; bool hasShape( SdrObject& rObject ) const;
/** returns the shape following the given shape in the list or 0 /** returns the shape the internal iterator points to, or 0 if
returns the first shape if pObj is 0 */ * the list end is reached. moves the internal iterator to the
SdrObject* getNextShape(SdrObject* pObj) const; * next shape. */
/**
*/
SdrObject* getNextShape(); SdrObject* getNextShape();
/** /** Sets the internal iterator to the shape at given index. */
*/
void seekShape( sal_uInt32 nIndex ); void seekShape( sal_uInt32 nIndex );
/** /**
......
...@@ -694,7 +694,7 @@ void SdDrawDocument::UpdateAllLinks() ...@@ -694,7 +694,7 @@ void SdDrawDocument::UpdateAllLinks()
*/ */
void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool ) void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool )
{ {
const sd::ShapeList& rPresentationShapes( pPage->GetPresentationShapeList() ); sd::ShapeList& rPresentationShapes( pPage->GetPresentationShapeList() );
if(!rPresentationShapes.isEmpty()) if(!rPresentationShapes.isEmpty())
{ {
// Create lists of title and outline styles // Create lists of title and outline styles
...@@ -706,11 +706,12 @@ void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool ...@@ -706,11 +706,12 @@ void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool
SfxStyleSheet* pTitleSheet = (SfxStyleSheet*)pSPool->GetTitleSheet(aName); SfxStyleSheet* pTitleSheet = (SfxStyleSheet*)pSPool->GetTitleSheet(aName);
SdrObject* pObj = rPresentationShapes.getNextShape(0); SdrObject* pObj = 0;
rPresentationShapes.seekShape(0);
// Now look for title and outline text objects, then make those objects // Now look for title and outline text objects, then make those objects
// listeners. // listeners.
while(pObj) while( (pObj = rPresentationShapes.getNextShape()) )
{ {
if (pObj->GetObjInventor() == SdrInventor) if (pObj->GetObjInventor() == SdrInventor)
{ {
...@@ -761,8 +762,6 @@ void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool ...@@ -761,8 +762,6 @@ void SdDrawDocument::NewOrLoadCompleted( SdPage* pPage, SdStyleSheetPool* pSPool
} }
} }
} }
pObj = rPresentationShapes.getNextShape(pObj);
} }
} }
} }
......
...@@ -156,7 +156,9 @@ SdrObject* SdPage::GetPresObj(PresObjKind eObjKind, int nIndex, bool bFuzzySearc ...@@ -156,7 +156,9 @@ SdrObject* SdPage::GetPresObj(PresObjKind eObjKind, int nIndex, bool bFuzzySearc
std::vector< SdrObject* > aMatches; std::vector< SdrObject* > aMatches;
SdrObject* pObj = 0; SdrObject* pObj = 0;
while( (pObj = maPresentationShapeList.getNextShape(pObj)) != 0 ) maPresentationShapeList.seekShape(0);
while( (pObj = maPresentationShapeList.getNextShape()) )
{ {
SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj); SdAnimationInfo* pInfo = SdDrawDocument::GetShapeUserData(*pObj);
if( pInfo ) if( pInfo )
...@@ -1572,11 +1574,11 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate ...@@ -1572,11 +1574,11 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate
// now delete all empty presentation objects that are no longer used by the new layout // now delete all empty presentation objects that are no longer used by the new layout
if( bInit ) if( bInit )
{ {
SdrObject* pObj = maPresentationShapeList.getNextShape(0); SdrObject* pObj = 0;
maPresentationShapeList.seekShape(0);
while( pObj ) while( (pObj = maPresentationShapeList.getNextShape()) )
{ {
SdrObject* pNext = maPresentationShapeList.getNextShape(pObj);
if( aUsedPresentationObjects.count(pObj) == 0 ) if( aUsedPresentationObjects.count(pObj) == 0 )
{ {
...@@ -1592,7 +1594,6 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate ...@@ -1592,7 +1594,6 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate
} }
/* #i108541# keep non empty pres obj as pres obj even if they are not part of the current layout */ /* #i108541# keep non empty pres obj as pres obj even if they are not part of the current layout */
} }
pObj = pNext;
} }
} }
} }
......
...@@ -379,9 +379,14 @@ SdPage::SdPage(const SdPage& rSrcPage) ...@@ -379,9 +379,14 @@ SdPage::SdPage(const SdPage& rSrcPage)
mePageKind = rSrcPage.mePageKind; mePageKind = rSrcPage.mePageKind;
meAutoLayout = rSrcPage.meAutoLayout; meAutoLayout = rSrcPage.meAutoLayout;
SdrObject* pObj = 0; // use shape list directly to preserve constness of rSrcPage
while((pObj = rSrcPage.maPresentationShapeList.getNextShape(pObj)) != 0) const std::list< SdrObject* >& rShapeList = rSrcPage.maPresentationShapeList.getList();
for( std::list< SdrObject* >::const_iterator aIter = rShapeList.begin();
aIter != rShapeList.end(); ++aIter )
{
SdrObject* pObj = *aIter;
InsertPresObj(GetObj(pObj->GetOrdNum()), rSrcPage.GetPresObjKind(pObj)); InsertPresObj(GetObj(pObj->GetOrdNum()), rSrcPage.GetPresObjKind(pObj));
}
mbSelected = sal_False; mbSelected = sal_False;
mnTransitionType = rSrcPage.mnTransitionType; mnTransitionType = rSrcPage.mnTransitionType;
......
...@@ -99,28 +99,6 @@ bool ShapeList::hasShape( SdrObject& rObject ) const ...@@ -99,28 +99,6 @@ bool ShapeList::hasShape( SdrObject& rObject ) const
return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end(); return std::find( maShapeList.begin(), maShapeList.end(), &rObject ) != maShapeList.end();
} }
SdrObject* ShapeList::getNextShape(SdrObject* pObj) const
{
if( pObj )
{
ListImpl::const_iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), pObj ) );
if( aIter != maShapeList.end() )
{
++aIter;
if( aIter != maShapeList.end() )
{
return (*aIter);
}
}
}
else if( !maShapeList.empty() )
{
return (*maShapeList.begin());
}
return 0;
}
void ShapeList::ObjectInDestruction(const SdrObject& rObject) void ShapeList::ObjectInDestruction(const SdrObject& rObject)
{ {
ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) ); ListImpl::iterator aIter( std::find( maShapeList.begin(), maShapeList.end(), &rObject ) );
......
...@@ -1060,8 +1060,9 @@ sal_Bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage) ...@@ -1060,8 +1060,9 @@ sal_Bool DrawViewShell::SwitchPage(sal_uInt16 nSelectedPage)
// set pages for all available handout presentation objects // set pages for all available handout presentation objects
sd::ShapeList& rShapeList = pMaster->GetPresentationShapeList(); sd::ShapeList& rShapeList = pMaster->GetPresentationShapeList();
SdrObject* pObj = 0; SdrObject* pObj = 0;
rShapeList.seekShape(0);
while( (pObj = rShapeList.getNextShape(pObj)) != 0 ) while( (pObj = rShapeList.getNextShape()) )
{ {
if( pMaster->GetPresObjKind(pObj) == PRESOBJ_HANDOUT ) if( pMaster->GetPresObjKind(pObj) == PRESOBJ_HANDOUT )
{ {
......
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