diff options
author | David Blaikie <dblaikie@gmail.com> | 2022-01-19 09:56:53 -0800 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2022-01-19 09:57:46 -0800 |
commit | baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810 (patch) | |
tree | d74edf10f07741a29f607fa50b493ffeb56818b4 /clang/lib/Serialization/ModuleManager.cpp | |
parent | eb5c0ea681803361a1944c966f4becaa9e22dc1a (diff) | |
download | llvm-baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810.zip llvm-baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810.tar.gz llvm-baa9b7c3c83ab6e4dfb15b8d7815a9958d5b5810.tar.bz2 |
unique_ptrify the ModuleManager's VisitState linked list
Diffstat (limited to 'clang/lib/Serialization/ModuleManager.cpp')
-rw-r--r-- | clang/lib/Serialization/ModuleManager.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index f4882c7..4fd217c 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, |