diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-07-31 16:35:49 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2017-07-13 12:10:29 +0200 |
commit | 36f93104d58abbe55cc4d245f4c81436a2b1eba5 (patch) | |
tree | 436bc9aa5e06e2dea6494de61e585f7a602edef5 /sw | |
parent | 00aa0892e7385cd8395dd39814077958be42e720 (diff) |
Don't update document stats for non-idle views
This functionality should be merged into the DocumentTimerManager,
which itself should run the different document idle tasks via
seperate jobs instead of a single idle, if they don't depend on
each other.
To implement a non-busy, suspendable Idle, this adds an AutoIdle
class, which is automatically re-scheduled after being processed.
It also adds a SwDocIdle, which isn't ready to schedule for busy
documents.
Change-Id: I185137ed3423ecaae0f7edb39018d26c4244d359
Diffstat (limited to 'sw')
-rw-r--r-- | sw/Library_sw.mk | 1 | ||||
-rw-r--r-- | sw/inc/SwDocIdle.hxx | 53 | ||||
-rw-r--r-- | sw/source/core/doc/DocumentStatisticsManager.cxx | 33 | ||||
-rw-r--r-- | sw/source/core/doc/SwDocIdle.cxx | 55 | ||||
-rw-r--r-- | sw/source/core/inc/DocumentStatisticsManager.hxx | 10 |
5 files changed, 131 insertions, 21 deletions
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 53e430ede61b..46b7693bc8ae 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -158,6 +158,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/core/crsr/trvltbl \ sw/source/core/crsr/viscrs \ sw/source/core/crsr/overlayrangesoutline \ + sw/source/core/doc/SwDocIdle \ sw/source/core/doc/SwStyleNameMapper \ sw/source/core/doc/acmplwrd \ sw/source/core/doc/CntntIdxStore \ diff --git a/sw/inc/SwDocIdle.hxx b/sw/inc/SwDocIdle.hxx new file mode 100644 index 000000000000..6bc65e24766c --- /dev/null +++ b/sw/inc/SwDocIdle.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_SW_INC_SWDOCIDLE_HXX +#define INCLUDED_SW_INC_SWDOCIDLE_HXX + +#include <doc.hxx> +#include <vcl/idle.hxx> + +namespace sw { + +/** + * An Idle, which is just ready to be scheduled for idle documents. + * + * Currently it's missing the notification, when busy documents become idle + * again, so it relies on any task being triggered to recheck, which is + * quite probably not a problem, as busy documents have a high chance to have + * generated idle tasks. + */ +class SwDocIdle : public AutoIdle +{ +private: + SwDoc &m_rDoc; + +protected: + virtual sal_uInt64 UpdateMinPeriod( + sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow ) const override; + +public: + SwDocIdle( SwDoc &doc ); + virtual ~SwDocIdle() override; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/DocumentStatisticsManager.cxx b/sw/source/core/doc/DocumentStatisticsManager.cxx index f529d5483417..9d050e0c77a0 100644 --- a/sw/source/core/doc/DocumentStatisticsManager.cxx +++ b/sw/source/core/doc/DocumentStatisticsManager.cxx @@ -34,6 +34,8 @@ #include <vector> #include <viewsh.hxx> #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <wrtsh.hxx> +#include <viewopt.hxx> using namespace ::com::sun::star; @@ -71,12 +73,13 @@ namespace sw DocumentStatisticsManager::DocumentStatisticsManager( SwDoc& i_rSwdoc ) : m_rDoc( i_rSwdoc ), mpDocStat( new SwDocStat ), - mbInitialized( false ) + mbInitialized( false ), + maStatsUpdateIdle( i_rSwdoc ) + { - maStatsUpdateTimer.SetTimeout( 1 ); - maStatsUpdateTimer.SetPriority( TaskPriority::LOWEST ); - maStatsUpdateTimer.SetInvokeHandler( LINK( this, DocumentStatisticsManager, DoIdleStatsUpdate ) ); - maStatsUpdateTimer.SetDebugName( "sw::DocumentStatisticsManager maStatsUpdateTimer" ); + maStatsUpdateIdle.SetPriority( TaskPriority::LOWEST ); + maStatsUpdateIdle.SetInvokeHandler( LINK( this, DocumentStatisticsManager, DoIdleStatsUpdate ) ); + maStatsUpdateIdle.SetDebugName( "sw::DocumentStatisticsManager maStatsUpdateIdle" ); } void DocumentStatisticsManager::DocInfoChgd(bool const isEnableSetModified) @@ -120,14 +123,15 @@ void DocumentStatisticsManager::UpdateDocStat( bool bCompleteAsync, bool bFields { if (!bCompleteAsync) { + maStatsUpdateIdle.Stop(); while (IncrementalDocStatCalculate( std::numeric_limits<long>::max(), bFields)) {} - maStatsUpdateTimer.Stop(); } - else if (IncrementalDocStatCalculate(5000, bFields)) - maStatsUpdateTimer.Start(); else - maStatsUpdateTimer.Stop(); + { + if (!maStatsUpdateIdle.IsActive() && IncrementalDocStatCalculate(5000, bFields)) + maStatsUpdateIdle.Start(); + } } } @@ -178,7 +182,7 @@ bool DocumentStatisticsManager::IncrementalDocStatCalculate(long nChars, bool bF } mpDocStat->nPage = m_rDoc.getIDocumentLayoutAccess().GetCurrentLayout() ? m_rDoc.getIDocumentLayoutAccess().GetCurrentLayout()->GetPageNum() : 0; - mpDocStat->bModified = false; + SetDocStatModified( false ); css::uno::Sequence < css::beans::NamedValue > aStat( mpDocStat->nPage ? 8 : 7); sal_Int32 n=0; @@ -233,11 +237,10 @@ bool DocumentStatisticsManager::IncrementalDocStatCalculate(long nChars, bool bF return nChars < 0; } -IMPL_LINK_NOARG( DocumentStatisticsManager, DoIdleStatsUpdate, Timer *, void ) +IMPL_LINK( DocumentStatisticsManager, DoIdleStatsUpdate, Timer *, pIdle, void ) { - if (IncrementalDocStatCalculate(32000)) - maStatsUpdateTimer.Start(); - + if (!IncrementalDocStatCalculate(32000)) + pIdle->Stop(); SwView* pView = m_rDoc.GetDocShell() ? m_rDoc.GetDocShell()->GetView() : nullptr; if( pView ) pView->UpdateDocStats(); @@ -245,7 +248,7 @@ IMPL_LINK_NOARG( DocumentStatisticsManager, DoIdleStatsUpdate, Timer *, void ) DocumentStatisticsManager::~DocumentStatisticsManager() { - maStatsUpdateTimer.Stop(); + maStatsUpdateIdle.Stop(); delete mpDocStat; } diff --git a/sw/source/core/doc/SwDocIdle.cxx b/sw/source/core/doc/SwDocIdle.cxx new file mode 100644 index 000000000000..9461807943d8 --- /dev/null +++ b/sw/source/core/doc/SwDocIdle.cxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <view.hxx> +#include <wrtsh.hxx> +#include <docsh.hxx> +#include <viewopt.hxx> +#include <vcl/scheduler.hxx> + +#include "SwDocIdle.hxx" + +namespace sw +{ + +sal_uInt64 SwDocIdle::UpdateMinPeriod( sal_uInt64 /* nMinPeriod */, sal_uInt64 /* nTimeNow */ ) const +{ + bool bReadyForSchedule = true; + SwView* pView = m_rDoc.GetDocShell() ? m_rDoc.GetDocShell()->GetView() : nullptr; + if( pView ) + { + SwWrtShell& rWrtShell = pView->GetWrtShell(); + bReadyForSchedule = rWrtShell.GetViewOptions()->IsIdle(); + } + return bReadyForSchedule + ? Scheduler::ImmediateTimeoutMs : Scheduler::InfiniteTimeoutMs; +} + +SwDocIdle::SwDocIdle( SwDoc &doc ) + : m_rDoc( doc ) +{ +} + +SwDocIdle::~SwDocIdle() +{ +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/inc/DocumentStatisticsManager.hxx b/sw/source/core/inc/DocumentStatisticsManager.hxx index b21e8ec9ef99..41b961f9cae5 100644 --- a/sw/source/core/inc/DocumentStatisticsManager.hxx +++ b/sw/source/core/inc/DocumentStatisticsManager.hxx @@ -20,11 +20,10 @@ #define INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTSTATISTICSMANAGER_HXX #include <IDocumentStatistics.hxx> -#include <vcl/timer.hxx> +#include <SwDocIdle.hxx> class SwDoc; struct SwDocStat; -class Timer; namespace sw { @@ -61,10 +60,9 @@ private: // Our own 'StatsUpdateTimer' calls the following method DECL_LINK( DoIdleStatsUpdate, Timer *, void ); - - SwDocStat *mpDocStat; //< Statistics information. - bool mbInitialized; // allow first time update - Timer maStatsUpdateTimer; //< Timer for asynchronous stats calculation + SwDocStat *mpDocStat; //< Statistics information + bool mbInitialized; //< allow first time update + SwDocIdle maStatsUpdateIdle; //< Idle for asynchronous stats calculation }; } |