diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-12-18 14:55:17 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-12-18 18:15:33 -0500 |
commit | b8e85af1eddb58ff60d93f64e157b31a904683b2 (patch) | |
tree | e6bbfc16a078c90f7810dc249649a7f9630db91c | |
parent | b9524c17b56e4bdecb76880582853fdeb3380013 (diff) |
Fine-tune our refresh policy during streaming.
Change-Id: I9eff0bc0e4087261e2283a55211c8a9daf2a8b24
-rw-r--r-- | sc/source/ui/docshell/datastream.cxx | 27 | ||||
-rw-r--r-- | sc/source/ui/inc/datastream.hxx | 3 |
2 files changed, 19 insertions, 11 deletions
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx index cbf8957ce223..f9686ae61edb 100644 --- a/sc/source/ui/docshell/datastream.cxx +++ b/sc/source/ui/docshell/datastream.cxx @@ -13,12 +13,12 @@ #include <com/sun/star/ui/XUIElement.hpp> #include <officecfg/Office/Common.hxx> #include <osl/conditn.hxx> +#include <osl/time.h> #include <rtl/strbuf.hxx> #include <salhelper/thread.hxx> #include <sfx2/linkmgr.hxx> #include <sfx2/viewfrm.hxx> #include <arealink.hxx> -#include <asciiopt.hxx> #include <datastreamdlg.hxx> #include <dbfunc.hxx> #include <docsh.hxx> @@ -42,6 +42,13 @@ namespace sc { +inline double getNow() +{ + TimeValue now; + osl_getSystemTime(&now); + return static_cast<double>(now.Seconds) + static_cast<double>(now.Nanosec) / 1000000000.0; +} + namespace datastreams { class CallerThread : public salhelper::Thread @@ -246,7 +253,8 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const ScRange& mbRunning(false), mpLines(0), mnLinesCount(0), - mnRepaintCounter(0), + mnLinesSinceRefresh(0), + mfLastRefreshTime(0.0), mnCurRow(0) { mxThread = new datastreams::CallerThread( this ); @@ -375,14 +383,11 @@ void DataStream::StopImport() void DataStream::Refresh() { - SCROW nEndRow = mpEndRange ? mpEndRange->aEnd.Row() : MAXROW; - ScRange aRange(maStartRange.aStart); - aRange.aEnd = ScAddress(maStartRange.aEnd.Col(), nEndRow, maStartRange.aStart.Tab()); - - mnRepaintCounter = 0; - // Hard recalc will repaint the grid area. mpDocShell->DoHardRecalc(true); + + mfLastRefreshTime = getNow(); + mnLinesSinceRefresh = 0; } void DataStream::MoveData() @@ -477,7 +482,7 @@ void DataStream::Text2Doc() orcus::csv_parser<CSVHandler> parser(aLine.getStr(), aLine.getLength(), aHdl, aConfig); parser.parse(); - ++mnRepaintCounter; + ++mnLinesSinceRefresh; } #else @@ -536,7 +541,9 @@ bool DataStream::ImportData() // maStartRange.aStart.Col(), mnCurRow, SC_FOLLOW_JUMP); } - if (mnRepaintCounter > 200) + if (getNow() - mfLastRefreshTime > 0.1 && mnLinesSinceRefresh > 200) + // Refresh no more frequently than every 0.1 second, and wait until at + // least we have processed 200 lines. Refresh(); return mbRunning; diff --git a/sc/source/ui/inc/datastream.hxx b/sc/source/ui/inc/datastream.hxx index 86be03b0964b..a593aad5f370 100644 --- a/sc/source/ui/inc/datastream.hxx +++ b/sc/source/ui/inc/datastream.hxx @@ -93,7 +93,8 @@ private: bool mbValuesInLine; LinesList* mpLines; size_t mnLinesCount; - size_t mnRepaintCounter; + size_t mnLinesSinceRefresh; + double mfLastRefreshTime; SCROW mnCurRow; ScRange maStartRange; boost::scoped_ptr<ScRange> mpEndRange; |