Commit ca151d07 authored by hjk's avatar hjk

CPlusPlus: Use QVector<Token> instead of QList

Better suited to avoid the indirection (sizeof(Token) > sizeof(void *))

Change-Id: Ia5f42781e720ef6aa8161f8f81ae8ddd8e58c837
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent cb1d040c
......@@ -59,7 +59,7 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor,
if (! suffix.isEmpty())
_text += suffix;
_tokens.append(_tokenize(_text, previousBlockState(_block)));
_tokens += _tokenize(_text, previousBlockState(_block));
_startToken = _tokens.size();
}
......@@ -85,7 +85,7 @@ const Token &BackwardsScanner::fetchToken(int tokenIndex)
_text.prepend(QLatin1Char('\n'));
_text.prepend(blockText);
QList<Token> adaptedTokens;
Tokens adaptedTokens;
for (int i = 0; i < _tokens.size(); ++i) {
Token t = _tokens.at(i);
t.utf16charOffset += blockText.length() + 1;
......
......@@ -77,7 +77,7 @@ private:
const Token &fetchToken(int tokenIndex);
private:
QList<Token> _tokens;
Tokens _tokens;
int _offset;
int _blocksTokenized;
QTextBlock _block;
......
......@@ -62,9 +62,9 @@ bool SimpleLexer::endedJoined() const
return _endedJoined;
}
QList<Token> SimpleLexer::operator()(const QString &text, int state)
Tokens SimpleLexer::operator()(const QString &text, int state)
{
QList<Token> tokens;
Tokens tokens;
const QByteArray bytes = text.toUtf8();
const char *firstChar = bytes.constData();
......@@ -113,7 +113,7 @@ QList<Token> SimpleLexer::operator()(const QString &text, int state)
return tokens;
}
int SimpleLexer::tokenAt(const QList<Token> &tokens, unsigned utf16charsOffset)
int SimpleLexer::tokenAt(const Tokens &tokens, unsigned utf16charsOffset)
{
for (int index = tokens.size() - 1; index >= 0; --index) {
const Token &tk = tokens.at(index);
......@@ -138,12 +138,12 @@ Token SimpleLexer::tokenAt(const QString &text,
features.cxx11Enabled = qtMocRunEnabled;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const QList<Token> tokens = tokenize(text, state);
const QVector<Token> tokens = tokenize(text, state);
const int tokenIdx = tokenAt(tokens, utf16charsOffset);
return (tokenIdx == -1) ? Token() : tokens.at(tokenIdx);
}
int SimpleLexer::tokenBefore(const QList<Token> &tokens, unsigned utf16charsOffset)
int SimpleLexer::tokenBefore(const Tokens &tokens, unsigned utf16charsOffset)
{
for (int index = tokens.size() - 1; index >= 0; --index) {
const Token &tk = tokens.at(index);
......
......@@ -34,12 +34,13 @@
#include <cplusplus/Token.h>
#include <QString>
#include <QList>
#include <QVector>
namespace CPlusPlus {
class SimpleLexer;
class Token;
typedef QVector<Token> Tokens;
class CPLUSPLUS_EXPORT SimpleLexer
{
......@@ -55,18 +56,18 @@ public:
bool endedJoined() const;
QList<Token> operator()(const QString &text, int state = 0);
Tokens operator()(const QString &text, int state = 0);
int state() const
{ return _lastState; }
static int tokenAt(const QList<Token> &tokens, unsigned utf16charsOffset);
static int tokenAt(const Tokens &tokens, unsigned utf16charsOffset);
static Token tokenAt(const QString &text,
unsigned utf16charsOffset,
int state,
bool qtMocRunEnabled = false);
static int tokenBefore(const QList<Token> &tokens, unsigned utf16charsOffset);
static int tokenBefore(const Tokens &tokens, unsigned utf16charsOffset);
private:
int _lastState;
......
......@@ -321,7 +321,7 @@ int ClangFunctionHintModel::activeArgument(const QString &prefix) const
int argnr = 0;
int parcount = 0;
SimpleLexer tokenize;
QList<CPlusPlus::Token> tokens = tokenize(prefix);
Tokens tokens = tokenize(prefix);
for (int i = 0; i < tokens.count(); ++i) {
const CPlusPlus::Token &tk = tokens.at(i);
if (tk.is(T_LPAREN))
......@@ -747,7 +747,7 @@ int ClangCompletionAssistProcessor::startOfOperator(int pos,
lf.objCEnabled = true;
tokenize.setLanguageFeatures(lf);
tokenize.setSkipComments(false);
const QList<CPlusPlus::Token> &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor
const CPlusPlus::Token tk = (tokenIdx == -1) ? CPlusPlus::Token() : tokens.at(tokenIdx);
......@@ -858,7 +858,7 @@ bool ClangCompletionAssistProcessor::accepts() const
lf.objCEnabled = true;
tokenize.setLanguageFeatures(lf);
tokenize.setSkipComments(false);
const QList<CPlusPlus::Token> &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1));
const CPlusPlus::Token tk = (tokenIdx == -1) ? CPlusPlus::Token() : tokens.at(tokenIdx);
......
......@@ -40,7 +40,7 @@ using namespace CppEditor;
using namespace Internal;
using namespace CPlusPlus;
static const Token tokenAtPosition(const QList<Token> &tokens, const unsigned pos)
static const Token tokenAtPosition(const Tokens &tokens, const unsigned pos)
{
for (int i = tokens.size() - 1; i >= 0; --i) {
const Token tk = tokens.at(i);
......@@ -63,7 +63,7 @@ static bool isInCommentHelper(const QTextCursor &cursor, Token *retToken = 0)
tokenize.setLanguageFeatures(features);
const int prevState = BackwardsScanner::previousBlockState(cursor.block()) & 0xFF;
const QList<Token> tokens = tokenize(cursor.block().text(), prevState);
const Tokens tokens = tokenize(cursor.block().text(), prevState);
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
......@@ -98,7 +98,7 @@ static bool isInStringHelper(const QTextCursor &cursor, Token *retToken = 0)
tokenize.setLanguageFeatures(features);
const int prevState = BackwardsScanner::previousBlockState(cursor.block()) & 0xFF;
const QList<Token> tokens = tokenize(cursor.block().text(), prevState);
const Tokens tokens = tokenize(cursor.block().text(), prevState);
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
......
......@@ -408,7 +408,7 @@ FollowSymbolUnderCursor::~FollowSymbolUnderCursor()
delete m_virtualFunctionAssistProvider;
}
static int skipMatchingParentheses(const QList<Token> &tokens, int idx, int initialDepth)
static int skipMatchingParentheses(const Tokens &tokens, int idx, int initialDepth)
{
int j = idx;
int depth = initialDepth;
......@@ -476,8 +476,7 @@ TextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &curs
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const QString blockText = cursor.block().text();
const QList<Token> tokens = tokenize(blockText,
BackwardsScanner::previousBlockState(cursor.block()));
const Tokens tokens = tokenize(blockText, BackwardsScanner::previousBlockState(cursor.block()));
bool recognizedQtMethod = false;
......
......@@ -85,7 +85,7 @@ void CppHighlighter::highlightBlock(const QString &text)
tokenize.setLanguageFeatures(features);
int initialLexerState = lexerState;
const QList<Token> tokens = tokenize(text, initialLexerState);
const Tokens tokens = tokenize(text, initialLexerState);
lexerState = tokenize.state(); // refresh lexer state
initialLexerState &= ~0x80; // discard newline expected bit
......
......@@ -95,7 +95,7 @@ CppTools::CheckSymbols *createHighlighter(const CPlusPlus::Document::Ptr &doc,
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const QList<Token> tokens = tokenize(name);
const Tokens tokens = tokenize(name);
if (tokens.length() && (tokens.at(0).isKeyword() || tokens.at(0).isObjCAtKeyword()))
continue;
......
......@@ -1449,7 +1449,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
*savedPaddingDepth = qMax(0, *savedPaddingDepth);
}
void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, int lexerState, int *indentDepth, int *paddingDepth) const
void QtStyleCodeFormatter::adjustIndent(const Tokens &tokens, int lexerState, int *indentDepth, int *paddingDepth) const
{
State topState = state();
State previousState = state(1);
......
......@@ -74,7 +74,7 @@ public:
protected:
virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth, int *paddingDepth, int *savedPaddingDepth) const = 0;
virtual void adjustIndent(const QList<CPlusPlus::Token> &tokens, int lexerState, int *indentDepth, int *paddingDepth) const = 0;
virtual void adjustIndent(const CPlusPlus::Tokens &tokens, int lexerState, int *indentDepth, int *paddingDepth) const = 0;
class State;
class BlockData
......@@ -251,7 +251,7 @@ private:
QStack<State> m_currentState;
QStack<State> m_newStates;
QList<CPlusPlus::Token> m_tokens;
CPlusPlus::Tokens m_tokens;
QString m_currentLine;
CPlusPlus::Token m_currentToken;
int m_tokenIndex;
......@@ -276,7 +276,7 @@ public:
protected:
virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth, int *paddingDepth, int *savedPaddingDepth) const;
virtual void adjustIndent(const QList<CPlusPlus::Token> &tokens, int lexerState, int *indentDepth, int *paddingDepth) const;
virtual void adjustIndent(const CPlusPlus::Tokens &tokens, int lexerState, int *indentDepth, int *paddingDepth) const;
virtual void saveBlockData(QTextBlock *block, const BlockData &data) const;
virtual bool loadBlockData(const QTextBlock &block, BlockData *data) const;
......
......@@ -387,7 +387,7 @@ int CppFunctionHintModel::activeArgument(const QString &prefix) const
int argnr = 0;
int parcount = 0;
SimpleLexer tokenize;
QList<Token> tokens = tokenize(prefix);
Tokens tokens = tokenize(prefix);
for (int i = 0; i < tokens.count(); ++i) {
const Token &tk = tokens.at(i);
if (tk.is(T_LPAREN))
......@@ -686,7 +686,7 @@ bool CppCompletionAssistProcessor::accepts() const
tokenize.setLanguageFeatures(features);
tokenize.setSkipComments(false);
const QList<Token> &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1));
const Token tk = (tokenIdx == -1) ? Token() : tokens.at(tokenIdx);
......@@ -789,7 +789,7 @@ int CppCompletionAssistProcessor::startOfOperator(int pos,
SimpleLexer tokenize;
tokenize.setLanguageFeatures(m_languageFeatures);
tokenize.setSkipComments(false);
const QList<Token> &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const Tokens &tokens = tokenize(tc.block().text(), BackwardsScanner::previousBlockState(tc.block()));
const int tokenIdx = SimpleLexer::tokenBefore(tokens, qMax(0, tc.positionInBlock() - 1)); // get the token at the left of the cursor
const Token tk = (tokenIdx == -1) ? Token() : tokens.at(tokenIdx);
......
......@@ -80,7 +80,7 @@ QString DoxygenGenerator::generate(QTextCursor cursor)
QTextBlock block = cursor.block();
while (block.isValid()) {
const QString &text = block.text();
const QList<Token> &tks = lexer(text);
const Tokens &tks = lexer(text);
foreach (const Token &tk, tks) {
if (tk.is(T_SEMICOLON) || tk.is(T_LBRACE)) {
// No need to continue beyond this, we might already have something meaningful.
......
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