unique_ptrify FileOutputBuffer::FileOutputBuffer

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216921 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie
2014-09-02 17:49:23 +00:00
parent 60a82bcf13
commit 98f518c81a
2 changed files with 8 additions and 11 deletions

View File

@ -77,7 +77,7 @@ private:
FileOutputBuffer(const FileOutputBuffer &) LLVM_DELETED_FUNCTION; FileOutputBuffer(const FileOutputBuffer &) LLVM_DELETED_FUNCTION;
FileOutputBuffer &operator=(const FileOutputBuffer &) LLVM_DELETED_FUNCTION; FileOutputBuffer &operator=(const FileOutputBuffer &) LLVM_DELETED_FUNCTION;
FileOutputBuffer(llvm::sys::fs::mapped_file_region *R, FileOutputBuffer(std::unique_ptr<llvm::sys::fs::mapped_file_region> R,
StringRef Path, StringRef TempPath); StringRef Path, StringRef TempPath);
std::unique_ptr<llvm::sys::fs::mapped_file_region> Region; std::unique_ptr<llvm::sys::fs::mapped_file_region> Region;

View File

@ -14,18 +14,16 @@
#include "llvm/Support/Errc.h" #include "llvm/Support/Errc.h"
#include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/FileOutputBuffer.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <system_error> #include <system_error>
using llvm::sys::fs::mapped_file_region; using llvm::sys::fs::mapped_file_region;
namespace llvm { namespace llvm {
FileOutputBuffer::FileOutputBuffer(mapped_file_region * R, FileOutputBuffer::FileOutputBuffer(std::unique_ptr<mapped_file_region> R,
StringRef Path, StringRef TmpPath) StringRef Path, StringRef TmpPath)
: Region(R) : Region(std::move(R)), FinalPath(Path), TempPath(TmpPath) {}
, FinalPath(Path)
, TempPath(TmpPath) {
}
FileOutputBuffer::~FileOutputBuffer() { FileOutputBuffer::~FileOutputBuffer() {
sys::fs::remove(Twine(TempPath)); sys::fs::remove(Twine(TempPath));
@ -73,14 +71,13 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size,
if (EC) if (EC)
return EC; return EC;
std::unique_ptr<mapped_file_region> MappedFile(new mapped_file_region( auto MappedFile = llvm::make_unique<mapped_file_region>(
FD, true, mapped_file_region::readwrite, Size, 0, EC)); FD, true, mapped_file_region::readwrite, Size, 0, EC);
if (EC) if (EC)
return EC; return EC;
Result.reset(new FileOutputBuffer(MappedFile.get(), FilePath, TempFilePath)); Result.reset(
if (Result) new FileOutputBuffer(std::move(MappedFile), FilePath, TempFilePath));
MappedFile.release();
return std::error_code(); return std::error_code();
} }