[clang] baa9b7c - unique_ptrify the ModuleManager's VisitState linked list
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 19 09:57:58 PST 2022
Author: David Blaikie
Date: 2022-01-19T09:57:46-08:00
New Revision: baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810
URL: https://github.com/llvm/llvm-project/commit/baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810
DIFF: https://github.com/llvm/llvm-project/commit/baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810.diff
LOG: unique_ptrify the ModuleManager's VisitState linked list
Added:
Modified:
clang/include/clang/Serialization/ModuleManager.h
clang/lib/Serialization/ModuleManager.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Serialization/ModuleManager.h b/clang/include/clang/Serialization/ModuleManager.h
index 7081eedad4b49..4305bae5ee958 100644
--- a/clang/include/clang/Serialization/ModuleManager.h
+++ b/clang/include/clang/Serialization/ModuleManager.h
@@ -105,10 +105,6 @@ class ModuleManager {
Stack.reserve(N);
}
- ~VisitState() {
- delete NextState;
- }
-
/// The stack used when marking the imports of a particular module
/// as not-to-be-visited.
SmallVector<ModuleFile *, 4> Stack;
@@ -121,14 +117,14 @@ class ModuleManager {
unsigned NextVisitNumber = 1;
/// The next visit state.
- VisitState *NextState = nullptr;
+ std::unique_ptr<VisitState> NextState;
};
/// The first visit() state in the chain.
- VisitState *FirstVisitState = nullptr;
+ std::unique_ptr<VisitState> FirstVisitState;
- VisitState *allocateVisitState();
- void returnVisitState(VisitState *State);
+ std::unique_ptr<VisitState> allocateVisitState();
+ void returnVisitState(std::unique_ptr<VisitState> State);
public:
using ModuleIterator = llvm::pointee_iterator<
@@ -142,7 +138,6 @@ class ModuleManager {
explicit ModuleManager(FileManager &FileMgr, InMemoryModuleCache &ModuleCache,
const PCHContainerReader &PCHContainerRdr,
const HeaderSearch &HeaderSearchInfo);
- ~ModuleManager();
/// Forward iterator to traverse all loaded modules.
ModuleIterator begin() { return Chain.begin(); }
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index f4882c7be3f7d..4fd217cf7a6ea 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -304,23 +304,22 @@ ModuleManager::addInMemoryBuffer(StringRef FileName,
InMemoryBuffers[Entry] = std::move(Buffer);
}
-ModuleManager::VisitState *ModuleManager::allocateVisitState() {
+std::unique_ptr<ModuleManager::VisitState> ModuleManager::allocateVisitState() {
// Fast path: if we have a cached state, use it.
if (FirstVisitState) {
- VisitState *Result = FirstVisitState;
- FirstVisitState = FirstVisitState->NextState;
- Result->NextState = nullptr;
+ auto Result = std::move(FirstVisitState);
+ FirstVisitState = std::move(Result->NextState);
return Result;
}
// Allocate and return a new state.
- return new VisitState(size());
+ return std::make_unique<VisitState>(size());
}
-void ModuleManager::returnVisitState(VisitState *State) {
+void ModuleManager::returnVisitState(std::unique_ptr<VisitState> State) {
assert(State->NextState == nullptr && "Visited state is in list?");
- State->NextState = FirstVisitState;
- FirstVisitState = State;
+ State->NextState = std::move(FirstVisitState);
+ FirstVisitState = std::move(State);
}
void ModuleManager::setGlobalIndex(GlobalModuleIndex *Index) {
@@ -351,8 +350,6 @@ ModuleManager::ModuleManager(FileManager &FileMgr,
: FileMgr(FileMgr), ModuleCache(&ModuleCache),
PCHContainerRdr(PCHContainerRdr), HeaderSearchInfo(HeaderSearchInfo) {}
-ModuleManager::~ModuleManager() { delete FirstVisitState; }
-
void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
llvm::SmallPtrSetImpl<ModuleFile *> *ModuleFilesHit) {
// If the visitation order vector is the wrong size, recompute the order.
@@ -396,11 +393,10 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
assert(VisitOrder.size() == N && "Visitation order is wrong?");
- delete FirstVisitState;
FirstVisitState = nullptr;
}
- VisitState *State = allocateVisitState();
+ auto State = allocateVisitState();
unsigned VisitNumber = State->NextVisitNumber++;
// If the caller has provided us with a hit-set that came from the global
@@ -452,7 +448,7 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
} while (true);
}
- returnVisitState(State);
+ returnVisitState(std::move(State));
}
bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
More information about the cfe-commits
mailing list