Skip to content

Commit

Permalink
Kill the Scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Apr 7, 2013
1 parent 9f93514 commit f04c275
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 277 deletions.
5 changes: 1 addition & 4 deletions src/CursorInfoJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ CursorInfoJob::CursorInfoJob(const Location &loc, const QueryMessage &query, con

void CursorInfoJob::execute()
{
Scope<const SymbolMap &> scope = project()->lockSymbolsForRead();
if (scope.isNull())
return;
const SymbolMap &map = scope.data();
const SymbolMap &map = project()->symbols();
if (map.isEmpty())
return;
SymbolMap::const_iterator it = RTags::findCursorInfo(map, location, context());
Expand Down
20 changes: 8 additions & 12 deletions src/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ void FileManager::recurseDirs()
{
shared_ptr<Project> project = mProject.lock();
assert(project);
shared_ptr<ScanJob> job(new ScanJob(project->path(), project));
job->finished().connect(this, &FileManager::onRecurseJobFinished);
shared_ptr<ScanJob> job(new ScanJob(project->path()));
job->finished().connectAsync(this, &FileManager::onRecurseJobFinished);
Server::instance()->threadPool()->start(job);
}

void FileManager::onRecurseJobFinished(const Set<Path> &paths)
void FileManager::onRecurseJobFinished(Set<Path> paths)
{
bool emitJS = false;
{
MutexLocker lock(&mMutex);
MutexLocker lock(&mMutex); // ### is this needed now?
Set<Path> old;
std::swap(mJSFiles, old);

shared_ptr<Project> project = mProject.lock();
assert(project);
Scope<FilesMap&> scope = project->lockFilesForWrite();
FilesMap &map = scope.data();
FilesMap &map = project->files();
mWatcher.clear();
for (Set<Path>::const_iterator it = paths.begin(); it != paths.end(); ++it) {
if (it->endsWith(".js"))
Expand Down Expand Up @@ -81,8 +80,7 @@ void FileManager::onFileAdded(const Path &path)

shared_ptr<Project> project = mProject.lock();
assert(project);
Scope<FilesMap&> scope = project->lockFilesForWrite();
FilesMap &map = scope.data();
FilesMap &map = project->files();
const Path parent = path.parentDir();
if (!parent.isEmpty()) {
Set<String> &dir = map[parent];
Expand All @@ -103,8 +101,7 @@ void FileManager::onFileRemoved(const Path &path)
{
MutexLocker lock(&mMutex);
shared_ptr<Project> project = mProject.lock();
Scope<FilesMap&> scope = project->lockFilesForWrite();
FilesMap &map = scope.data();
FilesMap &map = project->files();
if (map.contains(path)) {
recurseDirs();
return;
Expand Down Expand Up @@ -144,8 +141,7 @@ void FileManager::reload()
{
MutexLocker lock(&mMutex);
shared_ptr<Project> proj = mProject.lock();
Scope<FilesMap&> scope = proj->lockFilesForWrite();
FilesMap &map = scope.data();
FilesMap &map = proj->files();
map.clear();
recurseDirs();
}
Expand Down
5 changes: 3 additions & 2 deletions src/FileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
#include <rct/List.h>
#include <rct/FileSystemWatcher.h>
#include <rct/Mutex.h>
#include <rct/EventReceiver.h>
#include "Location.h"

class Project;
class FileManager
class FileManager : public EventReceiver
{
public:
FileManager();
void init(const shared_ptr<Project> &proj);
void recurseDirs();
void onFileAdded(const Path &path);
void onFileRemoved(const Path &path);
void onRecurseJobFinished(const Set<Path> &mPaths);
void onRecurseJobFinished(Set<Path> mPaths);
bool contains(const Path &path) const;
void reload();
Set<Path> jsFiles() const;
Expand Down
5 changes: 2 additions & 3 deletions src/FindFileJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ void FindFileJob::execute()
out.append(srcRoot);
assert(srcRoot.endsWith('/'));
}
Scope<const FilesMap&> scope = proj->lockFilesForRead();
const Map<Path, Set<String> > &dirs = scope.data();
Map<Path, Set<String> >::const_iterator dirit = dirs.begin();
const FilesMap& dirs = proj->files();
FilesMap::const_iterator dirit = dirs.begin();
bool foundExact = false;
const int patternSize = mPattern.size();
List<String> matches;
Expand Down
6 changes: 2 additions & 4 deletions src/FindSymbolsJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ void FindSymbolsJob::execute()
Map<Location, bool> out;
shared_ptr<Project> proj = project();
if (proj) {
Scope<const SymbolNameMap&> scope = proj->lockSymbolNamesForRead();
const SymbolNameMap &map = scope.data();
const SymbolNameMap &map = proj->symbolNames();
SymbolNameMap::const_iterator it = map.lower_bound(string);
while (it != map.end() && it->first.startsWith(string)) {
bool ok = false;
Expand All @@ -41,8 +40,7 @@ void FindSymbolsJob::execute()
}

if (out.size()) {
Scope<const SymbolMap&> scope = proj->lockSymbolsForRead();
const SymbolMap &map = scope.data();
const SymbolMap &map = proj->symbols();
List<RTags::SortedCursor> sorted;
sorted.reserve(out.size());
const bool declarationOnly = queryFlags() & QueryMessage::DeclarationOnly;
Expand Down
14 changes: 4 additions & 10 deletions src/FollowLocationJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ FollowLocationJob::FollowLocationJob(const Location &loc, const QueryMessage &qu

void FollowLocationJob::execute()
{
Scope<const SymbolMap&> scope = project()->lockSymbolsForRead();
if (scope.isNull())
return;
Scope<const ErrorSymbolMap&> errorScope = project()->lockErrorSymbolsForRead();
if (errorScope.isNull())
return;

const SymbolMap &map = scope.data();
const SymbolMap &map = project()->symbols();
const ErrorSymbolMap &errorSymbols = project()->errorSymbols();

const ErrorSymbolMap::const_iterator e = errorScope.data().find(location.fileId());
const SymbolMap *errors = e == errorScope.data().end() ? 0 : &e->second;
const ErrorSymbolMap::const_iterator e = errorSymbols.find(location.fileId());
const SymbolMap *errors = e == errorSymbols.end() ? 0 : &e->second;

bool foundInError = false;
SymbolMap::const_iterator it = RTags::findCursorInfo(map, location, context(), errors, &foundInError);
Expand Down
6 changes: 6 additions & 0 deletions src/IndexerJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ Location IndexerJob::createLocation(const CXSourceLocation &location, bool *bloc
mBlockedFiles.insert(fileId);
} else {
mVisitedFiles.insert(fileId);
if (mVisitedFiles.size() % 10 == 0) {
// We seem to get worse total performance when some
// translation units get to index all the headers.
// error() << "Sleeping some for" << mSourceInformation.sourceFile;
usleep(500000);
}
mData->errors[fileId] = 0;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/JSONJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ void JSONJob::execute()
{
shared_ptr<Project> proj = project();
const Path root = proj->path();
const DependencyMap deps = proj->dependencies();;
const DependencyMap deps = proj->dependencies();
// error() << deps.keys();
assert(proj);
Scope<const SymbolMap&> scope = proj->lockSymbolsForRead();
const SymbolMap &map = scope.data();
assert(!scope.isNull());
const SymbolMap &map = proj->symbols();
write("{");
bool firstObject = true;
for (DependencyMap::const_iterator it = deps.begin(); it != deps.end(); ++it) {
Expand Down
6 changes: 2 additions & 4 deletions src/ListSymbolsJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ Set<String> ListSymbolsJob::imenu(const shared_ptr<Project> &project)
{
Set<String> out;

Scope<const SymbolMap&> symbols = project->lockSymbolsForRead();
const SymbolMap &map = symbols.data();
const SymbolMap &map = project->symbols();
const List<String> paths = pathFilters();
if (paths.isEmpty()) {
error() << "--imenu must take path filters";
Expand Down Expand Up @@ -106,8 +105,7 @@ Set<String> ListSymbolsJob::listSymbols(const shared_ptr<Project> &project)
const bool hasFilter = Job::hasFilter();
const bool stripParentheses = queryFlags() & QueryMessage::StripParentheses;

Scope<const SymbolNameMap&> symbolNames = project->lockSymbolNamesForRead();
const SymbolNameMap &map = symbolNames.data();
const SymbolNameMap &map = project->symbolNames();
SymbolNameMap::const_iterator it = string.isEmpty() ? map.begin() : map.lower_bound(string);
int count = 0;
while (it != map.end()) {
Expand Down
Loading

0 comments on commit f04c275

Please sign in to comment.