Skip to content

Commit

Permalink
use std::make_shared and auto for exception safety
Browse files Browse the repository at this point in the history
  • Loading branch information
realwakka committed Dec 16, 2016
1 parent 66e1d80 commit bd8fa37
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void registerClasses(sel::State &state)

std::shared_ptr<AST> AST::create(const Source &source, const String &sourceCode, CXTranslationUnit unit)
{
std::shared_ptr<AST> ast(new AST);
auto ast = std::make_shared<AST>();
ast->mState.reset(new sel::State {true});
sel::State &state = *ast->mState;
registerClasses(state);
Expand Down
4 changes: 2 additions & 2 deletions src/CompletionThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void CompletionThread::printCompletions(const List<const Completions::Candidate
bool raw = false;
bool json = false;
if (request->conn) {
std::shared_ptr<Output> output(new Output);
auto output = std::make_shared<Output>();
output->connection = request->conn;
output->flags = request->flags;
outputs.append(output);
Expand All @@ -490,7 +490,7 @@ void CompletionThread::printCompletions(const List<const Completions::Candidate
log([&xml, &elisp, &outputs, &raw, &json](const std::shared_ptr<LogOutput> &output) {
// error() << "Got a dude" << output->testLog(RTags::DiagnosticsLevel);
if (output->testLog(RTags::DiagnosticsLevel)) {
std::shared_ptr<Output> out(new Output);
auto out = std::make_shared<Output>();
out->output = output;
if (output->flags() & RTagsLogOutput::Elisp) {
out->flags |= CompletionThread::Elisp;
Expand Down
6 changes: 3 additions & 3 deletions src/JobScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ JobScheduler::~JobScheduler()
void JobScheduler::add(const std::shared_ptr<IndexerJob> &job)
{
assert(!(job->flags & ~IndexerJob::Type_Mask));
std::shared_ptr<Node> node(new Node({ 0, job, 0, 0, 0, String() }));
std::shared_ptr<Node> node(new Node({0, job, 0, 0, 0, String()}));
node->job = job;
// error() << job->priority << job->sourceFile << mProcrastination;
if (mPendingJobs.isEmpty() || job->priority > mPendingJobs.first()->job->priority) {
Expand Down Expand Up @@ -155,7 +155,7 @@ void JobScheduler::startJobs()
delete process;
jobNode->job->flags |= IndexerJob::Crashed;
debug() << "job crashed (didn't start)" << jobId << jobNode->job->fileId() << jobNode->job.get();
std::shared_ptr<IndexDataMessage> msg(new IndexDataMessage(jobNode->job));
auto msg = std::make_shared<IndexDataMessage>(jobNode->job);
msg->setFlag(IndexDataMessage::ParseFailure);
jobFinished(jobNode->job, msg);
cont();
Expand Down Expand Up @@ -187,7 +187,7 @@ void JobScheduler::startJobs()
// job failed, probably no IndexDataMessage coming
n->job->flags |= IndexerJob::Crashed;
debug() << "job crashed" << jobId << n->job->fileId() << n->job.get();
std::shared_ptr<IndexDataMessage> msg(new IndexDataMessage(n->job));
auto msg = std::make_shared<IndexDataMessage>(n->job);
msg->setFlag(IndexDataMessage::ParseFailure);
jobFinished(n->job, msg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ int Project::startDirtyJobs(Dirty *dirty, Flags<IndexerJob::Flag> flags,
continue;
}

std::shared_ptr<IndexerJob> job(new IndexerJob(sources(fileId), flags, shared_from_this(), unsavedFiles));
auto job = std::make_shared<IndexerJob>(sources(fileId), flags, shared_from_this(), unsavedFiles);
if (wait) {
job->destroyed.connect([weakConn](IndexerJob *) {
// should arguably be refcounted but I don't know if anyone waits for multiple jobs
Expand Down Expand Up @@ -2413,7 +2413,7 @@ Source Project::source(uint32_t fileId, int buildIndex) const

void Project::reindex(uint32_t fileId, Flags<IndexerJob::Flag> flags)
{
index(std::shared_ptr<IndexerJob>(new IndexerJob(sources(fileId), flags, shared_from_this())));
index(std::make_shared<IndexerJob>(sources(fileId), flags, shared_from_this()));
}

void Project::processParseData(IndexParseData &&data)
Expand Down
4 changes: 2 additions & 2 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ class Project : public std::enable_shared_from_this<Project>
return it->second;
}
const Path path = project->sourceFilePath(fileId, Project::fileMapName(type));
std::shared_ptr<FileMap<Key, Value> > fileMap(new FileMap<Key, Value>);
auto fileMap = std::make_shared<FileMap<Key, Value>>();
String err;
if (fileMap->load(path, project->fileMapOptions(), &err)) {
++totalOpened;
cache[fileId] = fileMap;
std::shared_ptr<LRUEntry> entry(new LRUEntry(type, fileId));
auto entry = std::make_shared<LRUEntry>(type, fileId);
entryList.append(entry);
entryMap[entry->key] = entry;
if (++openedFiles > max) {
Expand Down
6 changes: 3 additions & 3 deletions src/QueryJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ QueryJob::QueryJob(const std::shared_ptr<QueryMessage> &query,
if (filter.mode == QueryMessage::PathFilter::Dependency) {
uint32_t f = Location::fileId(filter.pattern);
if (f && mProject)
mFilters.append(std::shared_ptr<Filter>(new DependencyFilter(f, mProject)));
mFilters.append(std::make_shared<DependencyFilter>(f, mProject));
} else if (query->flags() & QueryMessage::MatchRegex) {
mFilters.append(std::shared_ptr<Filter>(new RegexFilter(filter.pattern)));
mFilters.append(std::make_shared<RegexFilter>(filter.pattern));
} else {
mFilters.append(std::shared_ptr<Filter>(new PathFilter(filter.pattern)));
mFilters.append(std::make_shared<PathFilter>(filter.pattern));
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/RClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,30 +333,30 @@ RClient::~RClient()

void RClient::addQuery(QueryMessage::Type type, const String &query, Flags<QueryMessage::Flag> extraQueryFlags)
{
std::shared_ptr<QueryCommand> cmd(new QueryCommand(type, query));
auto cmd = std::make_shared<QueryCommand>(type, query);
cmd->extraQueryFlags = extraQueryFlags;
mCommands.append(cmd);
}

void RClient::addQuitCommand(int exitCode)
{
std::shared_ptr<QuitCommand> cmd(new QuitCommand(exitCode));
auto cmd = std::make_shared<QuitCommand>(exitCode);
mCommands.append(cmd);
}

void RClient::addLog(LogLevel level)
{
mCommands.append(std::shared_ptr<RCCommand>(new RdmLogCommand(level)));
mCommands.append(std::make_shared<RdmLogCommand>(level));
}

void RClient::addCompile(const String &args, const Path &cwd)
{
mCommands.append(std::shared_ptr<RCCommand>(new CompileCommand(args, cwd)));
mCommands.append(std::make_shared<CompileCommand>(args, cwd));
}

void RClient::addCompile(const Path &path)
{
mCommands.append(std::shared_ptr<RCCommand>(new CompileCommand(path)));
mCommands.append(std::make_shared<CompileCommand>(path));
}

int RClient::exec()
Expand Down
2 changes: 1 addition & 1 deletion src/RTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ std::shared_ptr<TranslationUnit> TranslationUnit::create(const Path &sourceFile,
bool displayDiagnostics)

{
std::shared_ptr<TranslationUnit> ret(new TranslationUnit);
auto ret = std::make_shared<TranslationUnit>();
ret->clangLine = "clang ";
ret->index = clang_createIndex(0, displayDiagnostics);

Expand Down
2 changes: 1 addition & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ void Server::handleIndexMessage(const std::shared_ptr<IndexMessage> &message, co

void Server::handleLogOutputMessage(const std::shared_ptr<LogOutputMessage> &message, const std::shared_ptr<Connection> &conn)
{
std::shared_ptr<RTagsLogOutput> log(new RTagsLogOutput(message->level(), message->flags(), conn));
auto log = std::make_shared<RTagsLogOutput>(message->level(), message->flags(), conn);
log->add();
}

Expand Down
2 changes: 1 addition & 1 deletion src/rdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ int main(int argc, char** argv)
EventLoop::SharedPtr loop(new EventLoop);
loop->init(EventLoop::MainEventLoop|EventLoop::EnableSigIntHandler|EventLoop::EnableSigTermHandler);

std::shared_ptr<Server> server(new Server);
auto server = std::make_shared<Server>();
if (!serverOpts.tests.isEmpty()) {
char buf[1024];
Path path;
Expand Down
2 changes: 1 addition & 1 deletion src/rp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, char **argv)
(void)closer;

RTags::initMessages();
std::shared_ptr<EventLoop> eventLoop(new EventLoop);
auto eventLoop = std::make_shared<EventLoop>();
eventLoop->init(EventLoop::MainEventLoop);
String data;

Expand Down

0 comments on commit bd8fa37

Please sign in to comment.