mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
Simplify memory ownership with std::unique_ptr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215567 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d6448b21bf
commit
c73a086233
@ -25,16 +25,6 @@ class TestObjectCache : public ObjectCache {
|
||||
public:
|
||||
TestObjectCache() : DuplicateInserted(false) { }
|
||||
|
||||
virtual ~TestObjectCache() {
|
||||
// Free any buffers we've allocated.
|
||||
SmallVectorImpl<MemoryBuffer *>::iterator it, end;
|
||||
end = AllocatedBuffers.end();
|
||||
for (it = AllocatedBuffers.begin(); it != end; ++it) {
|
||||
delete *it;
|
||||
}
|
||||
AllocatedBuffers.clear();
|
||||
}
|
||||
|
||||
virtual void notifyObjectCompiled(const Module *M, const MemoryBuffer *Obj) {
|
||||
// If we've seen this module before, note that.
|
||||
const std::string ModuleID = M->getModuleIdentifier();
|
||||
@ -75,14 +65,16 @@ public:
|
||||
private:
|
||||
MemoryBuffer *copyBuffer(const MemoryBuffer *Buf) {
|
||||
// Create a local copy of the buffer.
|
||||
MemoryBuffer *NewBuffer = MemoryBuffer::getMemBufferCopy(Buf->getBuffer());
|
||||
AllocatedBuffers.push_back(NewBuffer);
|
||||
return NewBuffer;
|
||||
std::unique_ptr<MemoryBuffer> NewBuffer(
|
||||
MemoryBuffer::getMemBufferCopy(Buf->getBuffer()));
|
||||
MemoryBuffer *Ret = NewBuffer.get();
|
||||
AllocatedBuffers.push_back(std::move(NewBuffer));
|
||||
return Ret;
|
||||
}
|
||||
|
||||
StringMap<const MemoryBuffer *> ObjMap;
|
||||
StringSet<> ModulesLookedUp;
|
||||
SmallVector<MemoryBuffer *, 2> AllocatedBuffers;
|
||||
SmallVector<std::unique_ptr<MemoryBuffer>, 2> AllocatedBuffers;
|
||||
bool DuplicateInserted;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user