forked from qt-creator/qt-creator
CPlusPlus: Microoptimizations
Inline some simple accessors, return references instead of copies in some getters, Change-Id: I136574823c79ad0c63ed354b78e1ad83908e7ae5 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -294,11 +294,6 @@ Document::~Document()
|
||||
_control = nullptr;
|
||||
}
|
||||
|
||||
Control *Document::control() const
|
||||
{
|
||||
return _control;
|
||||
}
|
||||
|
||||
Control *Document::swapControl(Control *newControl)
|
||||
{
|
||||
if (newControl) {
|
||||
@@ -318,41 +313,11 @@ Control *Document::swapControl(Control *newControl)
|
||||
return oldControl;
|
||||
}
|
||||
|
||||
unsigned Document::revision() const
|
||||
{
|
||||
return _revision;
|
||||
}
|
||||
|
||||
void Document::setRevision(unsigned revision)
|
||||
{
|
||||
_revision = revision;
|
||||
}
|
||||
|
||||
unsigned Document::editorRevision() const
|
||||
{
|
||||
return _editorRevision;
|
||||
}
|
||||
|
||||
void Document::setEditorRevision(unsigned editorRevision)
|
||||
{
|
||||
_editorRevision = editorRevision;
|
||||
}
|
||||
|
||||
QDateTime Document::lastModified() const
|
||||
{
|
||||
return _lastModified;
|
||||
}
|
||||
|
||||
void Document::setLastModified(const QDateTime &lastModified)
|
||||
{
|
||||
_lastModified = lastModified;
|
||||
}
|
||||
|
||||
QString Document::fileName() const
|
||||
{
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
QStringList Document::includedFiles() const
|
||||
{
|
||||
QStringList files;
|
||||
@@ -455,11 +420,6 @@ void Document::addUndefinedMacroUse(const QByteArray &name,
|
||||
\sa Document::macroUses(), Document::undefinedMacroUses()
|
||||
*/
|
||||
|
||||
TranslationUnit *Document::translationUnit() const
|
||||
{
|
||||
return _translationUnit;
|
||||
}
|
||||
|
||||
bool Document::skipFunctionBody() const
|
||||
{
|
||||
return _translationUnit->skipFunctionBody();
|
||||
@@ -483,11 +443,6 @@ Symbol *Document::globalSymbolAt(int index) const
|
||||
return _globalNamespace->memberAt(index);
|
||||
}
|
||||
|
||||
Namespace *Document::globalNamespace() const
|
||||
{
|
||||
return _globalNamespace;
|
||||
}
|
||||
|
||||
void Document::setGlobalNamespace(Namespace *globalNamespace)
|
||||
{
|
||||
_globalNamespace = globalNamespace;
|
||||
@@ -590,9 +545,6 @@ Document::Ptr Document::create(const QString &fileName)
|
||||
return doc;
|
||||
}
|
||||
|
||||
QByteArray Document::utf8Source() const
|
||||
{ return _source; }
|
||||
|
||||
void Document::setUtf8Source(const QByteArray &source)
|
||||
{
|
||||
_source = source;
|
||||
|
||||
@@ -62,16 +62,16 @@ public:
|
||||
public:
|
||||
~Document();
|
||||
|
||||
unsigned revision() const;
|
||||
void setRevision(unsigned revision);
|
||||
unsigned revision() const { return _revision; }
|
||||
void setRevision(unsigned revision) { _revision = revision; }
|
||||
|
||||
unsigned editorRevision() const;
|
||||
void setEditorRevision(unsigned editorRevision);
|
||||
unsigned editorRevision() const { return _editorRevision; }
|
||||
void setEditorRevision(unsigned editorRevision) { _editorRevision = editorRevision; }
|
||||
|
||||
QDateTime lastModified() const;
|
||||
const QDateTime &lastModified() const { return _lastModified; }
|
||||
void setLastModified(const QDateTime &lastModified);
|
||||
|
||||
QString fileName() const;
|
||||
const QString &fileName() const { return _fileName; }
|
||||
|
||||
void appendMacro(const Macro ¯o);
|
||||
void addMacroUse(const Macro ¯o,
|
||||
@@ -81,9 +81,9 @@ public:
|
||||
void addUndefinedMacroUse(const QByteArray &name,
|
||||
int bytesOffset, int utf16charsOffset);
|
||||
|
||||
Control *control() const;
|
||||
Control *control() const { return _control; }
|
||||
Control *swapControl(Control *newControl);
|
||||
TranslationUnit *translationUnit() const;
|
||||
TranslationUnit *translationUnit() const { return _translationUnit; }
|
||||
|
||||
bool skipFunctionBody() const;
|
||||
void setSkipFunctionBody(bool skipFunctionBody);
|
||||
@@ -91,23 +91,21 @@ public:
|
||||
int globalSymbolCount() const;
|
||||
Symbol *globalSymbolAt(int index) const;
|
||||
|
||||
Namespace *globalNamespace() const;
|
||||
Namespace *globalNamespace() const { return _globalNamespace; }
|
||||
void setGlobalNamespace(Namespace *globalNamespace); // ### internal
|
||||
|
||||
QList<Macro> definedMacros() const
|
||||
{ return _definedMacros; }
|
||||
const QList<Macro> &definedMacros() const { return _definedMacros; }
|
||||
|
||||
QString functionAt(int line, int column, int *lineOpeningDeclaratorParenthesis = nullptr,
|
||||
int *lineClosingBrace = nullptr) const;
|
||||
Symbol *lastVisibleSymbolAt(int line, int column = 0) const;
|
||||
Scope *scopeAt(int line, int column = 0);
|
||||
|
||||
QByteArray utf8Source() const;
|
||||
const QByteArray &utf8Source() const { return _source; }
|
||||
void setUtf8Source(const QByteArray &utf8Source);
|
||||
|
||||
QByteArray fingerprint() const { return m_fingerprint; }
|
||||
void setFingerprint(const QByteArray &fingerprint)
|
||||
{ m_fingerprint = fingerprint; }
|
||||
const QByteArray &fingerprint() const { return m_fingerprint; }
|
||||
void setFingerprint(const QByteArray &fingerprint) { m_fingerprint = fingerprint; }
|
||||
|
||||
LanguageFeatures languageFeatures() const;
|
||||
void setLanguageFeatures(LanguageFeatures features);
|
||||
@@ -173,7 +171,7 @@ public:
|
||||
bool isFatal() const
|
||||
{ return _level == Fatal; }
|
||||
|
||||
QString fileName() const
|
||||
const QString &fileName() const
|
||||
{ return _fileName; }
|
||||
|
||||
int line() const
|
||||
@@ -185,7 +183,7 @@ public:
|
||||
int length() const
|
||||
{ return _length; }
|
||||
|
||||
QString text() const
|
||||
const QString &text() const
|
||||
{ return _text; }
|
||||
|
||||
bool operator==(const DiagnosticMessage &other) const;
|
||||
@@ -206,7 +204,7 @@ public:
|
||||
void clearDiagnosticMessages()
|
||||
{ _diagnosticMessages.clear(); }
|
||||
|
||||
QList<DiagnosticMessage> diagnosticMessages() const
|
||||
const QList<DiagnosticMessage> &diagnosticMessages() const
|
||||
{ return _diagnosticMessages; }
|
||||
|
||||
class Block
|
||||
@@ -256,10 +254,10 @@ public:
|
||||
, _type(type)
|
||||
{ }
|
||||
|
||||
QString resolvedFileName() const
|
||||
const QString &resolvedFileName() const
|
||||
{ return _resolvedFileName; }
|
||||
|
||||
QString unresolvedFileName() const
|
||||
const QString &unresolvedFileName() const
|
||||
{ return _unresolvedFileName; }
|
||||
|
||||
int line() const
|
||||
@@ -290,7 +288,7 @@ public:
|
||||
bool isFunctionLike() const
|
||||
{ return _macro.isFunctionLike(); }
|
||||
|
||||
QVector<Block> arguments() const
|
||||
const QVector<Block> &arguments() const
|
||||
{ return _arguments; }
|
||||
|
||||
int beginLine() const
|
||||
@@ -327,19 +325,19 @@ public:
|
||||
QStringList includedFiles() const;
|
||||
void addIncludeFile(const Include &include);
|
||||
|
||||
QList<Include> resolvedIncludes() const
|
||||
const QList<Include> &resolvedIncludes() const
|
||||
{ return _resolvedIncludes; }
|
||||
|
||||
QList<Include> unresolvedIncludes() const
|
||||
const QList<Include> &unresolvedIncludes() const
|
||||
{ return _unresolvedIncludes; }
|
||||
|
||||
QList<Block> skippedBlocks() const
|
||||
const QList<Block> &skippedBlocks() const
|
||||
{ return _skippedBlocks; }
|
||||
|
||||
QList<MacroUse> macroUses() const
|
||||
const QList<MacroUse> macroUses() const
|
||||
{ return _macroUses; }
|
||||
|
||||
QList<UndefinedMacroUse> undefinedMacroUses() const
|
||||
const QList<UndefinedMacroUse> &undefinedMacroUses() const
|
||||
{ return _undefinedMacroUses; }
|
||||
|
||||
void setIncludeGuardMacroName(const QByteArray &includeGuardMacroName)
|
||||
|
||||
@@ -88,7 +88,7 @@ public:
|
||||
void addFormal(const QByteArray &formal)
|
||||
{ _formals.append(formal); }
|
||||
|
||||
QString fileName() const
|
||||
const QString &fileName() const
|
||||
{ return _fileName; }
|
||||
|
||||
void setFileName(const QString &fileName)
|
||||
|
||||
@@ -161,8 +161,7 @@ void TypeOfExpression::processEnvironment(Document::Ptr doc, Environment *env,
|
||||
for (const Document::Include &incl : includes)
|
||||
processEnvironment(m_snapshot.document(incl.resolvedFileName()), env, processed);
|
||||
|
||||
const QList<Macro> macros = doc->definedMacros();
|
||||
for (const Macro ¯o : macros)
|
||||
for (const Macro ¯o : doc->definedMacros())
|
||||
env->bind(macro);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,9 +111,7 @@ TestCases QtTestParser::testCases(const CppEditor::CppModelManager *modelManager
|
||||
if (document.isNull())
|
||||
return {};
|
||||
|
||||
const QList<CPlusPlus::Document::MacroUse> macros = document->macroUses();
|
||||
|
||||
for (const CPlusPlus::Document::MacroUse ¯o : macros) {
|
||||
for (const CPlusPlus::Document::MacroUse ¯o : document->macroUses()) {
|
||||
if (!macro.isFunctionLike())
|
||||
continue;
|
||||
const QByteArray name = macro.macro().name();
|
||||
|
||||
@@ -296,8 +296,7 @@ bool handleMacroCase(const Document::Ptr document,
|
||||
ranges->append(toRange(textCursor, macro->utf16CharOffset(), length));
|
||||
|
||||
// Other macro uses
|
||||
const QList<Document::MacroUse> macroUses = document->macroUses();
|
||||
for (const Document::MacroUse &use : macroUses) {
|
||||
for (const Document::MacroUse &use : document->macroUses()) {
|
||||
if (isMacroUseOf(use, *macro))
|
||||
ranges->append(toRange(textCursor, use.utf16charsBegin(), length));
|
||||
}
|
||||
|
||||
@@ -108,8 +108,7 @@ CheckSymbols *createHighlighter(const CPlusPlus::Document::Ptr &doc,
|
||||
using Utils::Text::convertPosition;
|
||||
|
||||
// Get macro definitions
|
||||
const QList<CPlusPlus::Macro> definedMacros = doc->definedMacros();
|
||||
for (const CPlusPlus::Macro ¯o : definedMacros) {
|
||||
for (const CPlusPlus::Macro ¯o : doc->definedMacros()) {
|
||||
int line, column;
|
||||
convertPosition(textDocument, macro.utf16CharOffset(), &line, &column);
|
||||
|
||||
@@ -120,8 +119,7 @@ CheckSymbols *createHighlighter(const CPlusPlus::Document::Ptr &doc,
|
||||
const LanguageFeatures features = doc->languageFeatures();
|
||||
|
||||
// Get macro uses
|
||||
const QList<Document::MacroUse> macroUseList = doc->macroUses();
|
||||
for (const Document::MacroUse ¯o : macroUseList) {
|
||||
for (const Document::MacroUse ¯o : doc->macroUses()) {
|
||||
const QString name = macro.macro().nameToQString();
|
||||
|
||||
//Filter out QtKeywords
|
||||
|
||||
@@ -1892,8 +1892,7 @@ void InternalCppCompletionAssistProcessor::addMacros_helper(const Snapshot &snap
|
||||
for (const Document::Include &i : includes)
|
||||
addMacros_helper(snapshot, i.resolvedFileName(), processed, definedMacros);
|
||||
|
||||
const QList<CPlusPlus::Macro> macros = doc->definedMacros();
|
||||
for (const CPlusPlus::Macro ¯o : macros) {
|
||||
for (const CPlusPlus::Macro ¯o : doc->definedMacros()) {
|
||||
const QString macroName = macro.nameToQString();
|
||||
if (!macro.isHidden())
|
||||
definedMacros->insert(macroName);
|
||||
|
||||
@@ -658,8 +658,7 @@ bool FromGuiFunctor::matchIncludeFile(const Document::Ptr &document, int line)
|
||||
|
||||
bool FromGuiFunctor::matchMacroInUse(const Document::Ptr &document, int pos)
|
||||
{
|
||||
const QList<Document::MacroUse> macros = document->macroUses();
|
||||
for (const Document::MacroUse &use : macros) {
|
||||
for (const Document::MacroUse &use : document->macroUses()) {
|
||||
if (use.containsUtf16charOffset(pos)) {
|
||||
const int begin = use.utf16charsBegin();
|
||||
if (pos < begin + use.macro().nameToQString().size()) {
|
||||
|
||||
@@ -732,8 +732,7 @@ restart_search:
|
||||
return usages;
|
||||
|
||||
usages.clear();
|
||||
const QList<CPlusPlus::Document::MacroUse> uses = doc->macroUses();
|
||||
for (const CPlusPlus::Document::MacroUse &use : uses) {
|
||||
for (const CPlusPlus::Document::MacroUse &use : doc->macroUses()) {
|
||||
const CPlusPlus::Macro &useMacro = use.macro();
|
||||
|
||||
if (useMacro.fileName() == macro.fileName()) { // Check if this is a match, but possibly against an outdated document.
|
||||
|
||||
@@ -207,8 +207,7 @@ Link findMacroLink_helper(const QByteArray &name, Document::Ptr doc, const Snaps
|
||||
if (doc && !name.startsWith('<') && !processed->contains(doc->fileName())) {
|
||||
processed->insert(doc->fileName());
|
||||
|
||||
const QList<Macro> macros = doc->definedMacros();
|
||||
for (const Macro ¯o : macros) {
|
||||
for (const Macro ¯o : doc->definedMacros()) {
|
||||
if (macro.name() == name) {
|
||||
Link link;
|
||||
link.targetFilePath = Utils::FilePath::fromString(macro.fileName());
|
||||
|
||||
@@ -187,8 +187,7 @@ void SourceProcessorTest::testMacroUses()
|
||||
|
||||
static bool isMacroDefinedInDocument(const QByteArray ¯oName, const Document::Ptr &document)
|
||||
{
|
||||
const QList<Macro> macros = document->definedMacros();
|
||||
for (const Macro ¯o : macros) {
|
||||
for (const Macro ¯o : document->definedMacros()) {
|
||||
if (macro.name() == macroName)
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -178,8 +178,7 @@ int LineForNewIncludeDirective::findInsertLineForVeryFirstInclude(unsigned *newL
|
||||
// If there is an include guard, insert right after that one
|
||||
const QByteArray includeGuardMacroName = m_cppDocument->includeGuardMacroName();
|
||||
if (!includeGuardMacroName.isEmpty()) {
|
||||
const QList<Macro> definedMacros = m_cppDocument->definedMacros();
|
||||
for (const Macro &definedMacro : definedMacros) {
|
||||
for (const Macro &definedMacro : m_cppDocument->definedMacros()) {
|
||||
if (definedMacro.name() == includeGuardMacroName) {
|
||||
if (newLinesToPrepend)
|
||||
*newLinesToPrepend = 1;
|
||||
|
||||
Reference in New Issue
Block a user