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;
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<
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(); }
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) {
: 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.
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
} while (true);
}
- returnVisitState(State);
+ returnVisitState(std::move(State));
}
bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,