unique_ptrify HeaderMap::FileBuffer

llvm-svn: 216758
This commit is contained in:
David Blaikie 2014-08-29 19:51:32 +00:00
parent 6d7b456184
commit 09844adc41
2 changed files with 8 additions and 12 deletions

View File

@ -17,6 +17,8 @@
#include "clang/Basic/LLVM.h"
#include "llvm/Support/Compiler.h"
#include <memory>
namespace llvm {
class MemoryBuffer;
}
@ -34,15 +36,12 @@ class HeaderMap {
HeaderMap(const HeaderMap &) LLVM_DELETED_FUNCTION;
void operator=(const HeaderMap &) LLVM_DELETED_FUNCTION;
const llvm::MemoryBuffer *FileBuffer;
std::unique_ptr<const llvm::MemoryBuffer> FileBuffer;
bool NeedsBSwap;
HeaderMap(const llvm::MemoryBuffer *File, bool BSwap)
: FileBuffer(File), NeedsBSwap(BSwap) {
}
HeaderMap(std::unique_ptr<const llvm::MemoryBuffer> File, bool BSwap)
: FileBuffer(std::move(File)), NeedsBSwap(BSwap) {}
public:
~HeaderMap();
/// HeaderMap::Create - This attempts to load the specified file as a header
/// map. If it doesn't look like a HeaderMap, it gives up and returns null.
static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);

View File

@ -81,7 +81,8 @@ const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
unsigned FileSize = FE->getSize();
if (FileSize <= sizeof(HMapHeader)) return nullptr;
std::unique_ptr<const llvm::MemoryBuffer> FileBuffer(FM.getBufferForFile(FE));
std::unique_ptr<const llvm::MemoryBuffer> FileBuffer =
FM.getBufferForFile(FE);
if (!FileBuffer) return nullptr; // Unreadable file?
const char *FileStart = FileBuffer->getBufferStart();
@ -103,11 +104,7 @@ const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
if (Header->Reserved != 0) return nullptr;
// Okay, everything looks good, create the header map.
return new HeaderMap(FileBuffer.release(), NeedsByteSwap);
}
HeaderMap::~HeaderMap() {
delete FileBuffer;
return new HeaderMap(std::move(FileBuffer), NeedsByteSwap);
}
//===----------------------------------------------------------------------===//