From 2b27f30538d165a14a5029580f722c8e9d417812 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 24 Oct 2016 12:51:03 +0200 Subject: [PATCH] AutoTest: Reduce re-parsings while editing single file Change-Id: If3dbcb3026733873881921cb9208b7c9da33c8de Reviewed-by: David Schulz --- src/plugins/autotest/testcodeparser.cpp | 49 ++++++++++++++++++++----- src/plugins/autotest/testcodeparser.h | 16 +++++--- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/plugins/autotest/testcodeparser.cpp b/src/plugins/autotest/testcodeparser.cpp index a30cd608a51..2cbf9f703e5 100644 --- a/src/plugins/autotest/testcodeparser.cpp +++ b/src/plugins/autotest/testcodeparser.cpp @@ -45,7 +45,6 @@ #include #include #include -#include static Q_LOGGING_CATEGORY(LOG, "qtc.autotest.testcodeparser") @@ -54,13 +53,7 @@ namespace Internal { TestCodeParser::TestCodeParser(TestTreeModel *parent) : QObject(parent), - m_model(parent), - m_codeModelParsing(false), - m_fullUpdatePostponed(false), - m_partialUpdatePostponed(false), - m_dirty(false), - m_singleShotScheduled(false), - m_parserState(Disabled) + m_model(parent) { // connect to ProgressManager to postpone test parsing when CppModelManager is parsing auto progressManager = qobject_cast(Core::ProgressManager::instance()); @@ -77,6 +70,8 @@ TestCodeParser::TestCodeParser(TestTreeModel *parent) emit testParseResultReady(m_futureWatcher.resultAt(index)); }); connect(this, &TestCodeParser::parsingFinished, this, &TestCodeParser::releaseParserInternals); + m_reparseTimer.setSingleShot(true); + connect(&m_reparseTimer, &QTimer::timeout, this, &TestCodeParser::parsePostponedFiles); } TestCodeParser::~TestCodeParser() @@ -111,7 +106,8 @@ void TestCodeParser::setState(State state) } else if (m_partialUpdatePostponed) { m_partialUpdatePostponed = false; qCDebug(LOG) << "calling scanForTests with postponed files (setState)"; - scanForTests(m_postponedFiles.toList()); + if (!m_reparseTimer.isActive()) + scanForTests(m_postponedFiles.toList()); } } } @@ -267,6 +263,30 @@ bool TestCodeParser::postponed(const QStringList &fileList) { switch (m_parserState) { case Idle: + if (fileList.size() == 1) { + if (m_reparseTimerTimedOut) + return false; + switch (m_postponedFiles.size()) { + case 0: + m_postponedFiles.insert(fileList.first()); + m_reparseTimer.setInterval(1000); + m_reparseTimer.start(); + return true; + case 1: + if (m_postponedFiles.contains(fileList.first())) { + m_reparseTimer.start(); + return true; + } + // intentional fall-through + default: + m_postponedFiles.insert(fileList.first()); + m_reparseTimer.stop(); + m_reparseTimer.setInterval(0); + m_reparseTimerTimedOut = false; + m_reparseTimer.start(); + return true; + } + } return false; case PartialParse: case FullParse: @@ -313,6 +333,8 @@ void TestCodeParser::scanForTests(const QStringList &fileList) if (postponed(fileList)) return; + m_reparseTimer.stop(); + m_reparseTimerTimedOut = false; m_postponedFiles.clear(); bool isFullParse = fileList.isEmpty(); QStringList list; @@ -436,7 +458,8 @@ void TestCodeParser::onPartialParsingFinished() } else if (m_partialUpdatePostponed) { m_partialUpdatePostponed = false; qCDebug(LOG) << "calling scanForTests with postponed files (onPartialParsingFinished)"; - scanForTests(m_postponedFiles.toList()); + if (!m_reparseTimer.isActive()) + scanForTests(m_postponedFiles.toList()); } else { m_dirty |= m_codeModelParsing; if (m_dirty) { @@ -454,6 +477,12 @@ void TestCodeParser::onPartialParsingFinished() } } +void TestCodeParser::parsePostponedFiles() +{ + m_reparseTimerTimedOut = true; + scanForTests(m_postponedFiles.toList()); +} + void TestCodeParser::releaseParserInternals() { for (ITestParser *parser : m_testCodeParsers) diff --git a/src/plugins/autotest/testcodeparser.h b/src/plugins/autotest/testcodeparser.h index ac095c14aac..9967c3d08b8 100644 --- a/src/plugins/autotest/testcodeparser.h +++ b/src/plugins/autotest/testcodeparser.h @@ -32,6 +32,7 @@ #include #include #include +#include namespace Core { class Id; @@ -89,19 +90,22 @@ private: void onAllTasksFinished(Core::Id type); void onFinished(); void onPartialParsingFinished(); + void parsePostponedFiles(); void releaseParserInternals(); TestTreeModel *m_model; - bool m_codeModelParsing; - bool m_fullUpdatePostponed; - bool m_partialUpdatePostponed; - bool m_dirty; - bool m_singleShotScheduled; + bool m_codeModelParsing = false; + bool m_fullUpdatePostponed = false; + bool m_partialUpdatePostponed = false; + bool m_dirty = false; + bool m_singleShotScheduled = false; + bool m_reparseTimerTimedOut = false; QSet m_postponedFiles; - State m_parserState; + State m_parserState = Disabled; QFutureWatcher m_futureWatcher; QVector m_testCodeParsers; // ptrs are still owned by TestFrameworkManager + QTimer m_reparseTimer; }; } // namespace Internal