llvm.org GIT mirror llvm / c73a086
Simplify memory ownership with std::unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215567 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
1 changed file(s) with 6 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
2424 public:
2525 TestObjectCache() : DuplicateInserted(false) { }
2626
27 virtual ~TestObjectCache() {
28 // Free any buffers we've allocated.
29 SmallVectorImpl::iterator it, end;
30 end = AllocatedBuffers.end();
31 for (it = AllocatedBuffers.begin(); it != end; ++it) {
32 delete *it;
33 }
34 AllocatedBuffers.clear();
35 }
36
3727 virtual void notifyObjectCompiled(const Module *M, const MemoryBuffer *Obj) {
3828 // If we've seen this module before, note that.
3929 const std::string ModuleID = M->getModuleIdentifier();
7464 private:
7565 MemoryBuffer *copyBuffer(const MemoryBuffer *Buf) {
7666 // Create a local copy of the buffer.
77 MemoryBuffer *NewBuffer = MemoryBuffer::getMemBufferCopy(Buf->getBuffer());
78 AllocatedBuffers.push_back(NewBuffer);
79 return NewBuffer;
67 std::unique_ptr NewBuffer(
68 MemoryBuffer::getMemBufferCopy(Buf->getBuffer()));
69 MemoryBuffer *Ret = NewBuffer.get();
70 AllocatedBuffers.push_back(std::move(NewBuffer));
71 return Ret;
8072 }
8173
8274 StringMap ObjMap;
8375 StringSet<> ModulesLookedUp;
84 SmallVector<MemoryBuffer *, 2> AllocatedBuffers;
76 SmallVector<std::unique_ptr, 2> AllocatedBuffers;
8577 bool DuplicateInserted;
8678 };
8779