forked from qt-creator/qt-creator
CompilationDatabase: Force QString implicit sharing
Most of the flags in compilation database are the same, let's share them by inserting them all into the temporary QSet of QString-s. Change-Id: I7d9b410b4b0bee40247434b49371bd37214d4c59 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -64,16 +64,18 @@ namespace Internal {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QStringList jsonObjectFlags(const QJsonObject &object)
|
QStringList jsonObjectFlags(const QJsonObject &object, QSet<QString> &flagsCache)
|
||||||
{
|
{
|
||||||
QStringList flags;
|
QStringList flags;
|
||||||
const QJsonArray arguments = object["arguments"].toArray();
|
const QJsonArray arguments = object["arguments"].toArray();
|
||||||
if (arguments.isEmpty()) {
|
if (arguments.isEmpty()) {
|
||||||
flags = splitCommandLine(object["command"].toString());
|
flags = splitCommandLine(object["command"].toString(), flagsCache);
|
||||||
} else {
|
} else {
|
||||||
flags.reserve(arguments.size());
|
flags.reserve(arguments.size());
|
||||||
for (const QJsonValue &arg : arguments)
|
for (const QJsonValue &arg : arguments) {
|
||||||
flags.append(arg.toString());
|
auto flagIt = flagsCache.insert(arg.toString());
|
||||||
|
flags.append(*flagIt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
@@ -339,6 +341,7 @@ std::vector<Entry> readJsonObjects(const QString &filePath)
|
|||||||
int objectStart = contents.indexOf('{');
|
int objectStart = contents.indexOf('{');
|
||||||
int objectEnd = contents.indexOf('}', objectStart + 1);
|
int objectEnd = contents.indexOf('}', objectStart + 1);
|
||||||
|
|
||||||
|
QSet<QString> flagsCache;
|
||||||
while (objectStart >= 0 && objectEnd >= 0) {
|
while (objectStart >= 0 && objectEnd >= 0) {
|
||||||
const QJsonDocument document = QJsonDocument::fromJson(
|
const QJsonDocument document = QJsonDocument::fromJson(
|
||||||
contents.mid(objectStart, objectEnd - objectStart + 1));
|
contents.mid(objectStart, objectEnd - objectStart + 1));
|
||||||
@@ -350,8 +353,8 @@ std::vector<Entry> readJsonObjects(const QString &filePath)
|
|||||||
|
|
||||||
const QJsonObject object = document.object();
|
const QJsonObject object = document.object();
|
||||||
const Utils::FileName fileName = jsonObjectFilename(object);
|
const Utils::FileName fileName = jsonObjectFilename(object);
|
||||||
const QStringList flags
|
const QStringList flags = filterFromFileName(jsonObjectFlags(object, flagsCache),
|
||||||
= filterFromFileName(jsonObjectFlags(object), fileName.toFileInfo().baseName());
|
fileName.toFileInfo().baseName());
|
||||||
result.push_back({flags, fileName, object["directory"].toString()});
|
result.push_back({flags, fileName, object["directory"].toString()});
|
||||||
|
|
||||||
objectStart = contents.indexOf('{', objectEnd + 1);
|
objectStart = contents.indexOf('{', objectEnd + 1);
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
@@ -205,7 +206,7 @@ void filteredFlags(const QString &fileName,
|
|||||||
flags = filtered;
|
flags = filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList splitCommandLine(QString commandLine)
|
QStringList splitCommandLine(QString commandLine, QSet<QString> &flagsCache)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
bool insideQuotes = false;
|
bool insideQuotes = false;
|
||||||
@@ -215,12 +216,19 @@ QStringList splitCommandLine(QString commandLine)
|
|||||||
for (const QString &part : commandLine.split(QRegularExpression("\""))) {
|
for (const QString &part : commandLine.split(QRegularExpression("\""))) {
|
||||||
if (insideQuotes) {
|
if (insideQuotes) {
|
||||||
const QString quotedPart = "\"" + part + "\"";
|
const QString quotedPart = "\"" + part + "\"";
|
||||||
if (result.last().endsWith("="))
|
if (result.last().endsWith("=")) {
|
||||||
result.last().append(quotedPart);
|
auto flagIt = flagsCache.insert(result.last() + quotedPart);
|
||||||
else
|
result.last() = *flagIt;
|
||||||
result.append(quotedPart);
|
} else {
|
||||||
|
auto flagIt = flagsCache.insert(quotedPart);
|
||||||
|
result.append(*flagIt);
|
||||||
|
}
|
||||||
} else { // If 's' is outside quotes ...
|
} else { // If 's' is outside quotes ...
|
||||||
result.append(part.split(QRegularExpression("\\s+"), QString::SkipEmptyParts));
|
for (const QString &flag :
|
||||||
|
part.split(QRegularExpression("\\s+"), QString::SkipEmptyParts)) {
|
||||||
|
auto flagIt = flagsCache.insert(flag);
|
||||||
|
result.append(*flagIt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
insideQuotes = !insideQuotes;
|
insideQuotes = !insideQuotes;
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,6 @@ void filteredFlags(const QString &fileName,
|
|||||||
QVector<ProjectExplorer::Macro> ¯os,
|
QVector<ProjectExplorer::Macro> ¯os,
|
||||||
CppTools::ProjectFile::Kind &fileKind);
|
CppTools::ProjectFile::Kind &fileKind);
|
||||||
|
|
||||||
QStringList splitCommandLine(QString commandLine);
|
QStringList splitCommandLine(QString commandLine, QSet<QString> &flagsCache);
|
||||||
|
|
||||||
} // namespace CompilationDatabaseProjectManager
|
} // namespace CompilationDatabaseProjectManager
|
||||||
|
Reference in New Issue
Block a user