Use shared_ptr in a couple more spots.

This commit is contained in:
Jacob Dufault 2017-06-09 21:15:33 -07:00
parent dec484ed0d
commit 64253ec174
2 changed files with 9 additions and 9 deletions

View File

@ -238,7 +238,7 @@ void BuildDetailString(CXCompletionString completion_string, std::string& label,
} }
void EnsureDocumentParsed(ClangCompleteManager* manager, void EnsureDocumentParsed(ClangCompleteManager* manager,
CompletionSession* session, std::shared_ptr<CompletionSession> session,
std::unique_ptr<clang::TranslationUnit>* tu, std::unique_ptr<clang::TranslationUnit>* tu,
clang::Index* index) { clang::Index* index) {
// Nothing to do. We already have a translation unit. // Nothing to do. We already have a translation unit.
@ -274,7 +274,7 @@ void CompletionParseMain(ClangCompleteManager* completion_manager) {
// If we don't get a session then that means we don't care about the file // If we don't get a session then that means we don't care about the file
// anymore - abandon the request. // anymore - abandon the request.
CompletionSession* session = completion_manager->TryGetSession(request.path, false /*create_if_needed*/); std::shared_ptr<CompletionSession> session = completion_manager->TryGetSession(request.path, false /*create_if_needed*/);
if (!session) if (!session)
continue; continue;
@ -302,7 +302,7 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) {
std::unique_ptr<ClangCompleteManager::CompletionRequest> request = completion_manager->completion_request_.Take(); std::unique_ptr<ClangCompleteManager::CompletionRequest> request = completion_manager->completion_request_.Take();
std::string path = request->location.textDocument.uri.GetPath(); std::string path = request->location.textDocument.uri.GetPath();
CompletionSession* session = completion_manager->TryGetSession(path, true /*create_if_needed*/); std::shared_ptr<CompletionSession> session = completion_manager->TryGetSession(path, true /*create_if_needed*/);
std::lock_guard<std::mutex> lock(session->tu_lock); std::lock_guard<std::mutex> lock(session->tu_lock);
EnsureDocumentParsed(completion_manager, session, &session->tu, &session->index); EnsureDocumentParsed(completion_manager, session, &session->tu, &session->index);
@ -386,10 +386,10 @@ CompletionSession::~CompletionSession() {}
LruSessionCache::LruSessionCache(int max_entries) : max_entries_(max_entries) {} LruSessionCache::LruSessionCache(int max_entries) : max_entries_(max_entries) {}
CompletionSession* LruSessionCache::TryGetEntry(const std::string& filename) { std::shared_ptr<CompletionSession> LruSessionCache::TryGetEntry(const std::string& filename) {
for (int i = 0; i < entries_.size(); ++i) { for (int i = 0; i < entries_.size(); ++i) {
if (entries_[i]->file.filename == filename) if (entries_[i]->file.filename == filename)
return entries_[i].get(); return entries_[i];
} }
return nullptr; return nullptr;
} }
@ -493,10 +493,10 @@ void ClangCompleteManager::NotifySave(const std::string& filename) {
parse_requests_.PriorityEnqueue(ParseRequest(filename)); parse_requests_.PriorityEnqueue(ParseRequest(filename));
} }
CompletionSession* ClangCompleteManager::TryGetSession(const std::string& filename, bool create_if_needed) { std::shared_ptr<CompletionSession> ClangCompleteManager::TryGetSession(const std::string& filename, bool create_if_needed) {
std::lock_guard<std::mutex> lock(sessions_lock_); std::lock_guard<std::mutex> lock(sessions_lock_);
CompletionSession* session = edit_sessions_.TryGetEntry(filename); std::shared_ptr<CompletionSession> session = edit_sessions_.TryGetEntry(filename);
if (!session) if (!session)
session = view_sessions_.TryGetEntry(filename); session = view_sessions_.TryGetEntry(filename);

View File

@ -41,7 +41,7 @@ struct LruSessionCache {
// Fetches the entry for |filename| and updates it's usage so it is less // Fetches the entry for |filename| and updates it's usage so it is less
// likely to be evicted. // likely to be evicted.
CompletionSession* TryGetEntry(const std::string& filename); std::shared_ptr<CompletionSession> TryGetEntry(const std::string& filename);
// TryGetEntry, except the return value captures ownership. // TryGetEntry, except the return value captures ownership.
std::shared_ptr<CompletionSession> TryTakeEntry(const std::string& fiilename); std::shared_ptr<CompletionSession> TryTakeEntry(const std::string& fiilename);
// Inserts an entry. Evicts the oldest unused entry if there is no space. // Inserts an entry. Evicts the oldest unused entry if there is no space.
@ -79,7 +79,7 @@ struct ClangCompleteManager {
// triggers a reparse. // triggers a reparse.
void NotifySave(const std::string& filename); void NotifySave(const std::string& filename);
CompletionSession* TryGetSession(const std::string& filename, bool create_if_needed); std::shared_ptr<CompletionSession> TryGetSession(const std::string& filename, bool create_if_needed);
// TODO: make these configurable. // TODO: make these configurable.
const int kMaxViewSessions = 3; const int kMaxViewSessions = 3;