[llvm] r211538 - Simplify memory management with std::unique_ptr.
Rafael Espindola
rafael.espindola at gmail.com
Mon Jun 23 14:15:27 PDT 2014
Author: rafael
Date: Mon Jun 23 16:15:27 2014
New Revision: 211538
URL: http://llvm.org/viewvc/llvm-project?rev=211538&view=rev
Log:
Simplify memory management with std::unique_ptr.
Modified:
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=211538&r1=211537&r2=211538&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Mon Jun 23 16:15:27 2014
@@ -683,10 +683,10 @@ static void writeStringTable(raw_fd_ostr
Out.seek(Pos);
}
-static void writeSymbolTable(
- raw_fd_ostream &Out, ArrayRef<NewArchiveIterator> Members,
- ArrayRef<MemoryBuffer *> Buffers,
- std::vector<std::pair<unsigned, unsigned> > &MemberOffsetRefs) {
+static void
+writeSymbolTable(raw_fd_ostream &Out, ArrayRef<NewArchiveIterator> Members,
+ ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
+ std::vector<std::pair<unsigned, unsigned>> &MemberOffsetRefs) {
unsigned StartOffset = 0;
unsigned MemberNum = 0;
std::string NameBuf;
@@ -696,7 +696,7 @@ static void writeSymbolTable(
for (ArrayRef<NewArchiveIterator>::iterator I = Members.begin(),
E = Members.end();
I != E; ++I, ++MemberNum) {
- MemoryBuffer *MemberBuffer = Buffers[MemberNum];
+ MemoryBuffer *MemberBuffer = Buffers[MemberNum].get();
ErrorOr<object::SymbolicFile *> ObjOrErr =
object::SymbolicFile::createSymbolicFile(
MemberBuffer, false, sys::fs::file_magic::unknown, &Context);
@@ -757,7 +757,7 @@ static void performWriteOperation(Archiv
std::vector<std::pair<unsigned, unsigned> > MemberOffsetRefs;
- std::vector<MemoryBuffer *> MemberBuffers;
+ std::vector<std::unique_ptr<MemoryBuffer>> MemberBuffers;
MemberBuffers.resize(NewMembers.size());
for (unsigned I = 0, N = NewMembers.size(); I < N; ++I) {
@@ -779,7 +779,7 @@ static void performWriteOperation(Archiv
failIfError(MemberBufferOrErr.getError());
MemberBuffer = std::move(MemberBufferOrErr.get());
}
- MemberBuffers[I] = MemberBuffer.release();
+ MemberBuffers[I].reset(MemberBuffer.release());
}
if (Symtab) {
@@ -807,7 +807,7 @@ static void performWriteOperation(Archiv
}
Out.seek(Pos);
- const MemoryBuffer *File = MemberBuffers[MemberNum];
+ const MemoryBuffer *File = MemberBuffers[MemberNum].get();
if (I->isNewMember()) {
const char *FileName = I->getNew();
const sys::fs::file_status &Status = I->getStatus();
@@ -843,10 +843,6 @@ static void performWriteOperation(Archiv
Out << '\n';
}
- for (unsigned I = 0, N = MemberBuffers.size(); I < N; ++I) {
- delete MemberBuffers[I];
- }
-
Output.keep();
Out.close();
sys::fs::rename(TemporaryOutput, ArchiveName);
More information about the llvm-commits
mailing list