summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2014-06-02 17:46:39 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2014-09-30 09:56:37 +0200
commit5c6f5f798e9d8671ad1ca3057e62931130250c49 (patch)
tree0213528be4302176ae245b9899fdb84e2cfb8c8c
parentf48e44a7bebe97ba3eefcdbf869c3fa4b6217a07 (diff)
Optimize AppendAllObjs for vectors
Removing items from large vectors, especially from the front, is very expensive. For a large mail merge job it took most of the time to memmove the descending vector items. Instead of remove, this simply overwrites the current with the last element. Change-Id: I12395388f4e315009602984acb443382fcce9f44 (cherry picked from commit a196a7575c48aaf6b5904565e18d31eacc80c855)
-rw-r--r--sw/source/core/layout/frmtool.cxx23
1 files changed, 16 insertions, 7 deletions
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index 8245f147905a..2ee6ab2b0ecd 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -1122,7 +1122,7 @@ static bool lcl_InHeaderOrFooter( SwFrmFmt& _rFmt )
return bRetVal;
}
-void AppendAllObjs( const SwFrmFmts *pTbl, const SwFrm* pSib )
+static void lcl_AppendAllObjs( const SwFrmFmts *pTbl, const SwFrm* pSib )
{
//Connecting of all Objects, which are described in the SpzTbl with the
//layout.
@@ -1137,9 +1137,10 @@ void AppendAllObjs( const SwFrmFmts *pTbl, const SwFrm* pSib )
while ( !aCpy.empty() && aCpy.size() != nOldCnt )
{
nOldCnt = aCpy.size();
- for ( int i = 0; i < int(aCpy.size()); ++i )
+ SwFrmFmts::iterator it = aCpy.begin();
+ while ( it != aCpy.end() )
{
- SwFrmFmt *pFmt = (SwFrmFmt*)aCpy[ sal_uInt16(i) ];
+ SwFrmFmt *pFmt = *it;
const SwFmtAnchor &rAnch = pFmt->GetAnchor();
sal_Bool bRemove = sal_False;
if ((rAnch.GetAnchorId() == FLY_AT_PAGE) ||
@@ -1163,9 +1164,17 @@ void AppendAllObjs( const SwFrmFmts *pTbl, const SwFrm* pSib )
}
if ( bRemove )
{
- aCpy.erase( aCpy.begin() + i );
- --i;
+ if ( (*it) != aCpy.back() ) {
+ (*it) = aCpy.back();
+ aCpy.pop_back();
+ }
+ else {
+ aCpy.pop_back();
+ it = aCpy.end();
+ }
}
+ else
+ it++;
}
}
aCpy.clear();
@@ -1563,7 +1572,7 @@ void _InsertCnt( SwLayoutFrm *pLay, SwDoc *pDoc,
if ( bPages ) //Jetzt noch die Flys verbinden lassen.
{
if ( !bDontCreateObjects )
- AppendAllObjs( pTbl, pLayout );
+ ::lcl_AppendAllObjs( pTbl, pLayout );
bObjsDirect = true;
}
@@ -1764,7 +1773,7 @@ void MakeFrms( SwDoc *pDoc, const SwNodeIndex &rSttIdx,
{
const SwFrmFmts *pTbl = pDoc->GetSpzFrmFmts();
if( !pTbl->empty() )
- AppendAllObjs( pTbl, pUpper );
+ ::lcl_AppendAllObjs( pTbl, pUpper );
}
// Wenn nichts eingefuegt wurde, z.B. ein ausgeblendeter Bereich,