Introduced a token cache for the C++ editor.

This should speed things up a bit, because before, the line was tokenized at
least 3 times.
This commit is contained in:
Erik Verbruggen
2010-06-04 09:36:05 +02:00
parent 414d9fe3e0
commit c2393df023
23 changed files with 244 additions and 86 deletions

View File

@@ -56,6 +56,7 @@
#include <cplusplus/BackwardsScanner.h>
#include <cplusplus/FastPreprocessor.h>
#include <cplusplus/CheckUndefinedSymbols.h>
#include <cplusplus/TokenCache.h>
#include <cpptools/cppmodelmanagerinterface.h>
@@ -534,7 +535,7 @@ struct FindCanonicalSymbol
SemanticInfo info;
FindCanonicalSymbol(CPPEditor *editor, const SemanticInfo &info)
: editor(editor), info(info)
: editor(editor), expressionUnderCursor(editor->tokenCache()), info(info)
{
typeOfExpression.init(info.doc, info.snapshot);
}
@@ -772,6 +773,11 @@ void CPPEditor::cut()
finishRename();
}
TokenCache *CPPEditor::tokenCache() const
{
return m_modelManager->tokenCache(editableInterface());
}
void CPPEditor::startRename()
{
m_inRenameChanged = false;
@@ -1251,7 +1257,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
SimpleLexer tokenize;
tokenize.setQtMocRunEnabled(true);
const QString blockText = cursor.block().text();
const QList<SimpleToken> tokens = tokenize(blockText, BackwardsScanner::previousBlockState(cursor.block()));
const QList<SimpleToken> tokens = tokenize(blockText, TokenCache::previousBlockState(cursor.block()));
bool recognizedQtMethod = false;
@@ -1301,7 +1307,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
static TokenUnderCursor tokenUnderCursor;
QTextBlock block;
const SimpleToken tk = tokenUnderCursor(tc, &block);
const SimpleToken tk = tokenUnderCursor(tokenCache(), tc, &block);
beginOfToken = block.position() + tk.begin();
endOfToken = block.position() + tk.end();
@@ -1331,7 +1337,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
return link;
// Evaluate the type of the expression under the cursor
ExpressionUnderCursor expressionUnderCursor;
ExpressionUnderCursor expressionUnderCursor(tokenCache());
const QString expression = expressionUnderCursor(tc);
TypeOfExpression typeOfExpression;
@@ -1430,13 +1436,13 @@ bool CPPEditor::isElectricCharacter(const QChar &ch) const
QString CPPEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text,
const QChar &la, int *skippedChars) const
{
MatchingText m;
MatchingText m(tokenCache());
return m.insertMatchingBrace(tc, text, la, skippedChars);
}
QString CPPEditor::insertParagraphSeparator(const QTextCursor &tc) const
{
MatchingText m;
MatchingText m(tokenCache());
return m.insertParagraphSeparator(tc);
}
@@ -1460,7 +1466,7 @@ bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
bool CPPEditor::isInComment(const QTextCursor &cursor) const
{
CPlusPlus::TokenUnderCursor tokenUnderCursor;
const SimpleToken tk = tokenUnderCursor(cursor);
const SimpleToken tk = tokenUnderCursor(tokenCache(), cursor);
if (tk.isComment()) {
const int pos = cursor.selectionEnd() - cursor.block().position();
@@ -1515,7 +1521,7 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
const TabSettings &ts = tabSettings();
BackwardsScanner tk(tc, QString(), 400);
BackwardsScanner tk(tokenCache(), tc, 400);
const int tokenCount = tk.startToken();
if (tokenCount != 0) {