diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2014-11-09 22:37:11 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2014-11-09 23:00:23 +0100 |
commit | bb95f7e6f7c9b1281875e6d729b66b6018794ee0 (patch) | |
tree | ad834f368fff21a8cdbe26a4b78238450df1c27e /sw | |
parent | 1a0f494be698dbb20ff7c7eb66fc84db498cfa45 (diff) |
speed up SwDoc::IsInHeaderFooter() by using SwFrmFmtAnchorMap
Now that it's possible to quickly find anchored objects for a node,
it's actually faster to check the node hiearchy rather than layout.
Change-Id: I5f93d5af32c744f1773535e5ec8537334d1ff58a
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/doc/doclay.cxx | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx index 8f12b98d230a..4bc37a0153ca 100644 --- a/sw/source/core/doc/doclay.cxx +++ b/sw/source/core/doc/doclay.cxx @@ -1512,43 +1512,42 @@ void SwDoc::SetAllUniqueFlyNames() bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const { - // If there's a Layout, use it! // That can also be a Fly in a Fly in the Header. // Is also used by sw3io, to determine if a Redline object is // in the Header or Footer. // Because Redlines are also attached to Start and EndNoden, // the Index must not necessarily be from a ContentNode. SwNode* pNd = &rIdx.GetNode(); - if( pNd->IsCntntNode() && getIDocumentLayoutAccess().GetCurrentViewShell() ) - { - const SwFrm *pFrm = pNd->GetCntntNode()->getLayoutFrm( getIDocumentLayoutAccess().GetCurrentLayout() ); - if( pFrm ) - { - const SwFrm *pUp = pFrm->GetUpper(); - while ( pUp && !pUp->IsHeaderFrm() && !pUp->IsFooterFrm() ) - { - if ( pUp->IsFlyFrm() ) - pUp = ((SwFlyFrm*)pUp)->GetAnchorFrm(); - pUp = pUp->GetUpper(); - } - if ( pUp ) - return true; - - return false; - } - } - const SwNode* pFlyNd = pNd->FindFlyStartNode(); while( pFlyNd ) { // get up by using the Anchor +#if OSL_DEBUG_LEVEL > 0 + std::list<const SwFrmFmt*> checkFmts; sal_uInt16 n; for( n = 0; n < GetSpzFrmFmts()->size(); ++n ) { const SwFrmFmt* pFmt = (*GetSpzFrmFmts())[ n ]; const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx(); if( pIdx && pFlyNd == &pIdx->GetNode() ) + checkFmts.push_back( pFmt ); + } +#endif + SwFrmFmtAnchorMap::const_iterator_pair range = GetFrmFmtAnchorMap()->equal_range( SwNodeIndex( *pFlyNd )); + SwFrmFmtAnchorMap::const_iterator it; + for( it = range.first; + it != range.second; + ++it ) + { + const SwFrmFmt* pFmt = it->second; + const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx(); + if( pIdx && pFlyNd == &pIdx->GetNode() ) { +#if OSL_DEBUG_LEVEL > 0 + std::list<const SwFrmFmt*>::iterator checkPos = std::find( checkFmts.begin(), checkFmts.end(), pFmt ); + assert( checkPos != checkFmts.end()); + checkFmts.erase( checkPos ); +#endif const SwFmtAnchor& rAnchor = pFmt->GetAnchor(); if ((FLY_AT_PAGE == rAnchor.GetAnchorId()) || !rAnchor.GetCntntAnchor() ) @@ -1561,11 +1560,14 @@ bool SwDoc::IsInHeaderFooter( const SwNodeIndex& rIdx ) const break; } } - if( n >= GetSpzFrmFmts()->size() ) + if( it == range.second ) { OSL_ENSURE( mbInReading, "Found a FlySection but not a Format!" ); return false; } +#if OSL_DEBUG_LEVEL > 0 + assert( checkFmts.empty()); +#endif } return 0 != pNd->FindHeaderStartNode() || |