Skip to content

Commit

Permalink
Make sources a list, instead of a set.
Browse files Browse the repository at this point in the history
Also, compare sources with one another only in IndexerJob::IndexerJob
  • Loading branch information
Andersbakken committed Dec 1, 2016
1 parent f3b6d8b commit 6e53b8a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/IncludeFileJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ IncludeFileJob::IncludeFileJob(const std::shared_ptr<QueryMessage> &query, const
: QueryJob(query, project)
{
const uint32_t fileId = Location::fileId(query->currentFile());
mSource = project->sources(fileId).toList().value(query->buildIndex());
mSource = project->sources(fileId).value(query->buildIndex());
if (mSource.isNull()) {
for (const uint32_t dep : project->dependencies(fileId, Project::DependsOnArg)) {
mSource = project->sources(dep).toList().value(query->buildIndex());
mSource = project->sources(dep).value(query->buildIndex());
if (!mSource.isNull())
break;
}
Expand Down
18 changes: 16 additions & 2 deletions src/IndexerJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,27 @@
#include "RTagsVersion.h"

uint64_t IndexerJob::sNextId = 1;
IndexerJob::IndexerJob(const Set<Source> &s,
IndexerJob::IndexerJob(const List<Source> &s,
Flags<Flag> f,
const std::shared_ptr<Project> &p,
const UnsavedFiles &u)
: id(0), sources(s), flags(f),
: id(0), flags(f),
project(p->path()), priority(0), unsavedFiles(u), crashCount(0)
{
sources.append(s.front());
for (size_t i=1; i<s.size(); ++i) {
const Source &src = s.at(i);
bool found = false;
for (size_t j=0; j<sources.size(); ++j) {
if (src.compareArguments(sources.at(j))) {
found = true;
break;
}
}
if (!found)
sources.append(src);
}

assert(!sources.isEmpty());
sourceFile = s.begin()->sourceFile();
acquireId();
Expand Down
4 changes: 2 additions & 2 deletions src/IndexerJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class IndexerJob

static String dumpFlags(Flags<Flag> flags);

IndexerJob(const Set<Source> &sources,
IndexerJob(const List<Source> &sources,
Flags<Flag> flags,
const std::shared_ptr<Project> &project,
const UnsavedFiles &unsavedFiles = UnsavedFiles());
Expand All @@ -50,7 +50,7 @@ class IndexerJob
uint32_t fileId() const { assert(!sources.isEmpty()); return sources.begin()->fileId; }

uint64_t id;
Set<Source> sources;
List<Source> sources;
Path sourceFile;
Flags<Flag> flags;
Path project;
Expand Down
6 changes: 3 additions & 3 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,9 +934,9 @@ void Project::onDirtyTimeout(Timer *)
debug() << "onDirtyTimeout" << dirtyFiles << dirtied;
}

Set<Source> Project::sources(uint32_t fileId) const
List<Source> Project::sources(uint32_t fileId) const
{
Set<Source> ret;
List<Source> ret;
forEachSources([&ret, fileId](const Sources &srcs) {
const auto it = srcs.find(fileId);
if (it != srcs.end())
Expand Down Expand Up @@ -2409,7 +2409,7 @@ void Project::processParseData(IndexParseData &&data)
} else {
forEachSource(data.sources, [this, &index](const Source &source) -> VisitResult {
auto &ref = mIndexParseData.sources[source.fileId];
if (ref.contains(source)) {
if (!ref.contains(source)) {
ref.append(source);
index.insert(source.fileId);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Project : public std::enable_shared_from_this<Project>
const IndexParseData &indexParseData() const { return mIndexParseData; }
void index(const std::shared_ptr<IndexerJob> &job);
void reindex(uint32_t fileId, Flags<IndexerJob::Flag> flags);
Set<Source> sources(uint32_t fileId) const;
List<Source> sources(uint32_t fileId) const;
Source source(uint32_t fileId, int buildIndex) const;
bool hasSource(uint32_t fileId) const;
bool isActiveJob(uint32_t sourceFileId) { return !sourceFileId || mActiveJobs.contains(sourceFileId); }
Expand Down
24 changes: 4 additions & 20 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,27 +559,11 @@ bool Server::parse(IndexParseData &data, String &&arguments, const Path &pwd, ui
}

if (shouldIndex(source, data.project)) {
bool found = false;
Project::forEachSources(data, [&found, &source](Sources &srcs) -> Project::VisitResult {
auto it = srcs.find(source.fileId);
if (it != srcs.end()) {
for (const Source &existingSource : it->second) {
if (existingSource.compareArguments(source)) {
found = true;
return Project::Stop;
}
}
}

return Project::Continue;
});

if (found)
continue;

Sources &s = compileCommandsFileId ? data.compileCommands[compileCommandsFileId].sources : data.sources;
source.compileCommandsFileId = compileCommandsFileId;
s[source.fileId].append(source);
auto &list = s[source.fileId];
if (!list.contains(source))
list.append(source);
ret = true;
}
}
Expand Down Expand Up @@ -1605,7 +1589,7 @@ void Server::sources(const std::shared_ptr<QueryMessage> &query, const std::shar
const uint32_t fileId = Location::fileId(path);
if (fileId) {
prepareCompletion(query, fileId, project);
Set<Source> sources = project->sources(fileId);
List<Source> sources = project->sources(fileId);
if (sources.isEmpty() && path.isHeader()) {
Set<uint32_t> seen;
std::function<uint32_t(uint32_t)> findSourceFileId = [&findSourceFileId, &project, &seen](uint32_t file) {
Expand Down

0 comments on commit 6e53b8a

Please sign in to comment.