Commit 13c3972a authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

ExtraCompiler: Use a hash for contents

Avoid recurring scans of the targets.

From a simple test, there is usually a single target. This is mostly
done for correctness.

Change-Id: Ic025de0825133f1096c400278c929a7e9087c643
Reviewed-by: default avatarUlf Hermann <ulf.hermann@theqtcompany.com>
parent b692c137
......@@ -51,8 +51,8 @@ class ExtraCompilerPrivate
public:
const Project *project;
Utils::FileName source;
QHash<Utils::FileName, QByteArray> contents;
Utils::FileNameList targets;
QVector<QByteArray> contents;
QList<Task> issues;
QDateTime compileTime;
Core::IEditor *lastEditor = 0;
......@@ -71,7 +71,8 @@ ExtraCompiler::ExtraCompiler(const Project *project, const Utils::FileName &sour
d->project = project;
d->source = source;
d->targets = targets;
d->contents.resize(targets.size());
foreach (const Utils::FileName &target, targets)
d->contents.insert(target, QByteArray());
d->timer.setSingleShot(true);
connect(d->project, &Project::activeTargetChanged, this, &ExtraCompiler::onActiveTargetChanged);
......@@ -148,11 +149,7 @@ Utils::FileName ExtraCompiler::source() const
QByteArray ExtraCompiler::content(const Utils::FileName &file) const
{
for (int i = 0; i < d->targets.length(); ++i) {
if (d->targets[i] == file)
return d->contents[i];
}
return QByteArray();
return d->contents.value(file);
}
Utils::FileNameList ExtraCompiler::targets() const
......@@ -335,13 +332,11 @@ void ExtraCompilerPrivate::updateIssues()
void ExtraCompiler::setContent(const Utils::FileName &file, const QByteArray &contents)
{
for (int i = 0; i < d->targets.length(); ++i) {
if (d->targets[i] == file) {
if (d->contents[i] != contents) {
d->contents[i] = contents;
emit contentsChanged(file);
}
return;
auto it = d->contents.find(file);
if (it != d->contents.end()) {
if (it.value() != contents) {
it.value() = contents;
emit contentsChanged(file);
}
}
}
......
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