Kaydet (Commit) b63766b3 authored tarafından Caolán McNamara's avatar Caolán McNamara

Resolves: fdo#48932 super slow typing and scrolling in large documents

AFAICS it appears that theres a one to one mapping from a SwFrameControl to
a SwFrm, so in any of the three given classes of Page, Footer or Header a
SwFrm will have zero or one SwFrameControls and a SwFrameControl doesn't
get rebound to a different SwFrm or anything like that, so we can use
a map and index off the SwFrm* to find them rather than constantly
looping over vectors to find the right one.

Maybe could move the SwFrameControl directly in the SwPageFrm's
themselves.

Change-Id: I1194f3cdcab747b61c645003c97e651f47f2bc09
üst 993a807a
...@@ -37,21 +37,6 @@ ...@@ -37,21 +37,6 @@
using namespace std; using namespace std;
namespace
{
class FramePredicate
{
const SwFrm* m_pToMatch;
public:
FramePredicate( const SwFrm* pFrm ) : m_pToMatch( pFrm ) { };
virtual ~FramePredicate() {};
virtual bool operator()( SwFrameControlPtr pToCheck )
{ return m_pToMatch == pToCheck->GetFrame(); };
};
}
SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) : SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
m_pEditWin( pEditWin ), m_pEditWin( pEditWin ),
m_aControls( ) m_aControls( )
...@@ -60,14 +45,6 @@ SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) : ...@@ -60,14 +45,6 @@ SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
SwFrameControlsManager::~SwFrameControlsManager() SwFrameControlsManager::~SwFrameControlsManager()
{ {
map< FrameControlType, vector< SwFrameControlPtr > >::iterator pIt = m_aControls.begin();
while ( pIt != m_aControls.end() )
{
pIt->second.clear( );
++pIt;
}
m_aControls.clear();
} }
SwFrameControlsManager::SwFrameControlsManager( const SwFrameControlsManager& rCopy ) : SwFrameControlsManager::SwFrameControlsManager( const SwFrameControlsManager& rCopy ) :
...@@ -85,68 +62,60 @@ const SwFrameControlsManager& SwFrameControlsManager::operator=( const SwFrameCo ...@@ -85,68 +62,60 @@ const SwFrameControlsManager& SwFrameControlsManager::operator=( const SwFrameCo
SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrm* pFrm ) SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrm* pFrm )
{ {
SwFrameControlPtr pControl; SwFrameControlPtrMap& rControls = m_aControls[eType];
vector< SwFrameControlPtr >& aControls = m_aControls[eType];
vector< SwFrameControlPtr >::iterator pIt = find_if( SwFrameControlPtrMap::iterator aIt = rControls.find(pFrm);
aControls.begin(), aControls.end( ), FramePredicate( pFrm ) );
if ( pIt != aControls.end() ) if (aIt != rControls.end())
pControl = *pIt; return aIt->second;
return pControl; return SwFrameControlPtr();
} }
void SwFrameControlsManager::AddControl( FrameControlType eType, SwFrameControlPtr pControl ) void SwFrameControlsManager::AddControl( FrameControlType eType, SwFrameControlPtr pControl )
{ {
m_aControls[eType].push_back( pControl ); m_aControls[eType].insert(make_pair(pControl->GetFrame(), pControl));
} }
void SwFrameControlsManager::RemoveControls( const SwFrm* pFrm ) void SwFrameControlsManager::RemoveControls( const SwFrm* pFrm )
{ {
map< FrameControlType, vector< SwFrameControlPtr > >::iterator pIt = m_aControls.begin(); map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
while ( pIt != m_aControls.end() ) while ( pIt != m_aControls.end() )
{ {
vector< SwFrameControlPtr >& aVect = pIt->second; SwFrameControlPtrMap& rMap = pIt->second;
aVect.erase( remove_if( aVect.begin(), rMap.erase(pFrm);
aVect.end(),
FramePredicate( pFrm ) ), aVect.end() );
++pIt; ++pIt;
} }
} }
void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrm* pFrm ) void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrm* pFrm )
{ {
vector< SwFrameControlPtr >& aVect = m_aControls[eType]; SwFrameControlPtrMap& rMap = m_aControls[eType];
aVect.erase( remove_if( aVect.begin(), rMap.erase(pFrm);
aVect.end(),
FramePredicate( pFrm ) ), aVect.end() );
} }
void SwFrameControlsManager::HideControls( FrameControlType eType ) void SwFrameControlsManager::HideControls( FrameControlType eType )
{ {
vector< SwFrameControlPtr >::iterator pIt = m_aControls[eType].begin(); SwFrameControlPtrMap::iterator pIt = m_aControls[eType].begin();
while ( pIt != m_aControls[eType].end() ) while ( pIt != m_aControls[eType].end() )
{ {
( *pIt )->ShowAll( false ); pIt->second->ShowAll( false );
++pIt; ++pIt;
} }
} }
void SwFrameControlsManager::SetReadonlyControls( bool bReadonly ) void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
{ {
map< FrameControlType, vector< SwFrameControlPtr > >::iterator pIt = m_aControls.begin(); map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
while ( pIt != m_aControls.end() ) while ( pIt != m_aControls.end() )
{ {
vector< SwFrameControlPtr >::iterator pVectIt = pIt->second.begin(); SwFrameControlPtrMap::iterator aCtrlIt = pIt->second.begin();
while ( pVectIt != pIt->second.end() ) while ( aCtrlIt != pIt->second.end() )
{ {
( *pVectIt )->SetReadonly( bReadonly ); aCtrlIt->second->SetReadonly( bReadonly );
++pVectIt; ++aCtrlIt;
} }
++pIt; ++pIt;
} }
...@@ -160,27 +129,22 @@ void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm, ...@@ -160,27 +129,22 @@ void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm,
SwFrameControlPtr pControl; SwFrameControlPtr pControl;
const bool bHeader = ( eType == Header ); const bool bHeader = ( eType == Header );
vector< SwFrameControlPtr >& aControls = m_aControls[eType]; SwFrameControlPtrMap& rControls = m_aControls[eType];
vector< SwFrameControlPtr >::iterator pIt = aControls.begin();
while ( pIt != aControls.end() && !pControl.get() )
{
SwHeaderFooterWin* pToTest = dynamic_cast< SwHeaderFooterWin* >( pIt->get() );
if ( pToTest->GetPageFrame( ) == pPageFrm &&
pToTest->IsHeader( ) == bHeader )
pControl = *pIt;
++pIt;
}
if ( !pControl.get() ) SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
pControl = lb->second;
else
{ {
SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) ); SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) );
const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions(); const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
pNewControl->SetReadonly( pViewOpt->IsReadonly() ); pNewControl->SetReadonly( pViewOpt->IsReadonly() );
AddControl( eType, pNewControl ); rControls.insert(lb, make_pair(pPageFrm, pNewControl));
pControl.swap( pNewControl ); pControl.swap( pNewControl );
} }
assert(pControl->IsHeader() == bHeader);
Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() ); Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() );
SwHeaderFooterWin* pHFWin = dynamic_cast< SwHeaderFooterWin* >( pControl.get() ); SwHeaderFooterWin* pHFWin = dynamic_cast< SwHeaderFooterWin* >( pControl.get() );
...@@ -195,23 +159,19 @@ void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm ) ...@@ -195,23 +159,19 @@ void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
// Check if we already have the control // Check if we already have the control
SwFrameControlPtr pControl; SwFrameControlPtr pControl;
vector< SwFrameControlPtr >& aControls = m_aControls[PageBreak]; SwFrameControlPtrMap& rControls = m_aControls[PageBreak];
vector< SwFrameControlPtr >::iterator pIt = aControls.begin(); SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
while ( pIt != aControls.end() && !pControl.get() ) if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
{ pControl = lb->second;
SwPageBreakWin* pToTest = dynamic_cast< SwPageBreakWin* >( pIt->get() ); else
if ( pToTest->GetPageFrame( ) == pPageFrm )
pControl = *pIt;
++pIt;
}
if ( !pControl.get() )
{ {
SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) ); SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) );
const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions(); const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
pNewControl->SetReadonly( pViewOpt->IsReadonly() ); pNewControl->SetReadonly( pViewOpt->IsReadonly() );
AddControl( PageBreak, pNewControl );
rControls.insert(lb, make_pair(pPageFrm, pNewControl));
pControl.swap( pNewControl ); pControl.swap( pNewControl );
} }
......
...@@ -42,13 +42,15 @@ class SwEditWin; ...@@ -42,13 +42,15 @@ class SwEditWin;
typedef boost::shared_ptr< SwFrameControl > SwFrameControlPtr; typedef boost::shared_ptr< SwFrameControl > SwFrameControlPtr;
typedef std::map<const SwFrm*, SwFrameControlPtr> SwFrameControlPtrMap;
/** A container for the Header/Footer, or PageBreak controls. /** A container for the Header/Footer, or PageBreak controls.
*/ */
class SwFrameControlsManager class SwFrameControlsManager
{ {
private: private:
SwEditWin* m_pEditWin; SwEditWin* m_pEditWin;
std::map< FrameControlType, std::vector< SwFrameControlPtr > > m_aControls; std::map< FrameControlType, SwFrameControlPtrMap > m_aControls;
public: public:
SwFrameControlsManager( SwEditWin* pEditWin ); SwFrameControlsManager( SwEditWin* pEditWin );
......
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