forked from qt-creator/qt-creator
Reduce the CPU usage of the semantic highlighter.
This commit is contained in:
@@ -51,6 +51,12 @@ using namespace CppEditor::Internal;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
class FriendlyThread: public QThread
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using QThread::msleep;
|
||||||
|
};
|
||||||
|
|
||||||
class CollectTypes: protected SymbolVisitor
|
class CollectTypes: protected SymbolVisitor
|
||||||
{
|
{
|
||||||
Document::Ptr _doc;
|
Document::Ptr _doc;
|
||||||
@@ -281,6 +287,7 @@ protected:
|
|||||||
CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &context)
|
CheckSymbols::Future CheckSymbols::go(Document::Ptr doc, const LookupContext &context)
|
||||||
{
|
{
|
||||||
Q_ASSERT(doc);
|
Q_ASSERT(doc);
|
||||||
|
|
||||||
return (new CheckSymbols(doc, context))->start();
|
return (new CheckSymbols(doc, context))->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,21 +307,17 @@ CheckSymbols::~CheckSymbols()
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
void CheckSymbols::run()
|
void CheckSymbols::run()
|
||||||
{
|
|
||||||
if (! isCanceled())
|
|
||||||
runFunctor();
|
|
||||||
|
|
||||||
reportFinished();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckSymbols::runFunctor()
|
|
||||||
{
|
{
|
||||||
_diagnosticMessages.clear();
|
_diagnosticMessages.clear();
|
||||||
|
|
||||||
|
if (! isCanceled()) {
|
||||||
if (_doc->translationUnit()) {
|
if (_doc->translationUnit()) {
|
||||||
accept(_doc->translationUnit()->ast());
|
accept(_doc->translationUnit()->ast());
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reportFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckSymbols::warning(unsigned line, unsigned column, const QString &text, unsigned length)
|
bool CheckSymbols::warning(unsigned line, unsigned column, const QString &text, unsigned length)
|
||||||
@@ -687,6 +690,7 @@ void CheckSymbols::flush()
|
|||||||
if (_usages.isEmpty())
|
if (_usages.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
FriendlyThread::msleep(10); // release some cpu
|
||||||
reportResults(_usages);
|
reportResults(_usages);
|
||||||
_usages.clear();
|
_usages.clear();
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,8 @@ namespace CPlusPlus {
|
|||||||
|
|
||||||
class CheckSymbols:
|
class CheckSymbols:
|
||||||
protected ASTVisitor,
|
protected ASTVisitor,
|
||||||
public QtConcurrent::RunFunctionTaskBase<CppEditor::Internal::SemanticInfo::Use>
|
public QRunnable,
|
||||||
|
public QFutureInterface<CppEditor::Internal::SemanticInfo::Use>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~CheckSymbols();
|
virtual ~CheckSymbols();
|
||||||
@@ -51,9 +52,18 @@ public:
|
|||||||
typedef CppEditor::Internal::SemanticInfo::Use Use;
|
typedef CppEditor::Internal::SemanticInfo::Use Use;
|
||||||
|
|
||||||
virtual void run();
|
virtual void run();
|
||||||
void runFunctor();
|
|
||||||
|
|
||||||
typedef QFuture<Use> Future;
|
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 Future go(Document::Ptr doc, const LookupContext &context);
|
||||||
|
|
||||||
static QMap<int, QVector<Use> > chunks(const QFuture<Use> &future, int from, int to)
|
static QMap<int, QVector<Use> > chunks(const QFuture<Use> &future, int from, int to)
|
||||||
|
Reference in New Issue
Block a user