From f6490e047a853bb38d435b8039bbeb4b41e863d3 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 8 Nov 2017 22:57:48 +0000 Subject: [FileOutputBuffer] Move factory methods out of their classes. InMemoryBuffer and OnDiskBuffer classes have both factory methods and public constructors, and that looks a bit odd. This patch makes factory methods non-member function to fix it. Differential Revision: https://reviews.llvm.org/D39693 llvm-svn: 317739 --- llvm/lib/Support/FileOutputBuffer.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'llvm/lib/Support/FileOutputBuffer.cpp') diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp index 8906be3aaa2..db8ff38e5b5 100644 --- a/llvm/lib/Support/FileOutputBuffer.cpp +++ b/llvm/lib/Support/FileOutputBuffer.cpp @@ -38,9 +38,6 @@ public: std::unique_ptr Buf) : FileOutputBuffer(Path), Buffer(std::move(Buf)), TempPath(TempPath) {} - static Expected> - create(StringRef Path, size_t Size, unsigned Mode); - uint8_t *getBufferStart() const override { return (uint8_t *)Buffer->data(); } uint8_t *getBufferEnd() const override { @@ -78,16 +75,6 @@ public: InMemoryBuffer(StringRef Path, MemoryBlock Buf, unsigned Mode) : FileOutputBuffer(Path), Buffer(Buf), Mode(Mode) {} - static Expected> - create(StringRef Path, size_t Size, unsigned Mode) { - std::error_code EC; - MemoryBlock MB = Memory::allocateMappedMemory( - Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC); - if (EC) - return errorCodeToError(EC); - return llvm::make_unique(Path, MB, Mode); - } - uint8_t *getBufferStart() const override { return (uint8_t *)Buffer.base(); } uint8_t *getBufferEnd() const override { @@ -111,8 +98,18 @@ private: unsigned Mode; }; -Expected> -OnDiskBuffer::create(StringRef Path, size_t Size, unsigned Mode) { +static Expected> +createInMemoryBuffer(StringRef Path, size_t Size, unsigned Mode) { + std::error_code EC; + MemoryBlock MB = Memory::allocateMappedMemory( + Size, nullptr, sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC); + if (EC) + return errorCodeToError(EC); + return llvm::make_unique(Path, MB, Mode); +} + +static Expected> +createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) { // Create new file in same directory but with random name. SmallString<128> TempPath; int FD; @@ -165,8 +162,8 @@ FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) { case fs::file_type::regular_file: case fs::file_type::file_not_found: case fs::file_type::status_error: - return OnDiskBuffer::create(Path, Size, Mode); + return createOnDiskBuffer(Path, Size, Mode); default: - return InMemoryBuffer::create(Path, Size, Mode); + return createInMemoryBuffer(Path, Size, Mode); } } -- cgit v1.2.3