Commit 99b64924 authored by Roberto Raggi's avatar Roberto Raggi

Reduce the CPU usage of the semantic highlighter.

parent 867bf3da
......@@ -51,6 +51,12 @@ using namespace CppEditor::Internal;
namespace {
class FriendlyThread: public QThread
{
public:
using QThread::msleep;
};
class CollectTypes: protected SymbolVisitor
{
Document::Ptr _doc;
......@@ -281,6 +287,7 @@ protected:
CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &context)
{
Q_ASSERT(doc);
return (new CheckSymbols(doc, context))->start();
}
......@@ -300,21 +307,17 @@ CheckSymbols::~CheckSymbols()
{ }
void CheckSymbols::run()
{
if (! isCanceled())
runFunctor();
reportFinished();
}
void CheckSymbols::runFunctor()
{
_diagnosticMessages.clear();
if (_doc->translationUnit()) {
accept(_doc->translationUnit()->ast());
flush();
if (! isCanceled()) {
if (_doc->translationUnit()) {
accept(_doc->translationUnit()->ast());
flush();
}
}
reportFinished();
}
bool CheckSymbols::warning(unsigned line, unsigned column, const QString &text, unsigned length)
......@@ -687,6 +690,7 @@ void CheckSymbols::flush()
if (_usages.isEmpty())
return;
FriendlyThread::msleep(10); // release some cpu
reportResults(_usages);
_usages.clear();
}
......@@ -43,7 +43,8 @@ namespace CPlusPlus {
class CheckSymbols:
protected ASTVisitor,
public QtConcurrent::RunFunctionTaskBase<CppEditor::Internal::SemanticInfo::Use>
public QRunnable,
public QFutureInterface<CppEditor::Internal::SemanticInfo::Use>
{
public:
virtual ~CheckSymbols();
......@@ -51,9 +52,18 @@ public:
typedef CppEditor::Internal::SemanticInfo::Use Use;
virtual void run();
void runFunctor();
typedef QFuture<Use> Future;
Future start()
{
this->setRunnable(this);
this->reportStarted();
Future future = this->future();
QThreadPool::globalInstance()->start(this, QThread::IdlePriority);
return future;
}
static Future go(Document::Ptr doc, const LookupContext &context);
static QMap<int, QVector<Use> > chunks(const QFuture<Use> &future, int from, int to)
......
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