aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-08-22 19:00:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-11-13 20:39:49 +0000
commitfe6060f10f634930ff71b7c50291ddc610da2475 (patch)
tree1483580c790bd4d27b6500a7542b5ee00534d3cc /contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp
parentb61bce17f346d79cecfd8f195a64b10f77be43b1 (diff)
parent344a3780b2e33f6ca763666c380202b18aab72a3 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp30
1 files changed, 11 insertions, 19 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp b/contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp
index 3342682270dc..4b4406c4c9f4 100644
--- a/contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/contrib/llvm-project/llvm/lib/Support/FileOutputBuffer.cpp
@@ -33,21 +33,20 @@ namespace {
// with the temporary file on commit().
class OnDiskBuffer : public FileOutputBuffer {
public:
- OnDiskBuffer(StringRef Path, fs::TempFile Temp,
- std::unique_ptr<fs::mapped_file_region> Buf)
+ OnDiskBuffer(StringRef Path, fs::TempFile Temp, fs::mapped_file_region Buf)
: FileOutputBuffer(Path), Buffer(std::move(Buf)), Temp(std::move(Temp)) {}
- uint8_t *getBufferStart() const override { return (uint8_t *)Buffer->data(); }
+ uint8_t *getBufferStart() const override { return (uint8_t *)Buffer.data(); }
uint8_t *getBufferEnd() const override {
- return (uint8_t *)Buffer->data() + Buffer->size();
+ return (uint8_t *)Buffer.data() + Buffer.size();
}
- size_t getBufferSize() const override { return Buffer->size(); }
+ size_t getBufferSize() const override { return Buffer.size(); }
Error commit() override {
// Unmap buffer, letting OS flush dirty pages to file on disk.
- Buffer.reset();
+ Buffer.unmap();
// Atomically replace the existing file with the new one.
return Temp.keep(FinalPath);
@@ -56,7 +55,7 @@ public:
~OnDiskBuffer() override {
// Close the mapping before deleting the temp file, so that the removal
// succeeds.
- Buffer.reset();
+ Buffer.unmap();
consumeError(Temp.discard());
}
@@ -67,7 +66,7 @@ public:
}
private:
- std::unique_ptr<fs::mapped_file_region> Buffer;
+ fs::mapped_file_region Buffer;
fs::TempFile Temp;
};
@@ -132,23 +131,16 @@ createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) {
return FileOrErr.takeError();
fs::TempFile File = std::move(*FileOrErr);
-#ifndef _WIN32
- // On Windows, CreateFileMapping (the mmap function on Windows)
- // automatically extends the underlying file. We don't need to
- // extend the file beforehand. _chsize (ftruncate on Windows) is
- // pretty slow just like it writes specified amount of bytes,
- // so we should avoid calling that function.
- if (auto EC = fs::resize_file(File.FD, Size)) {
+ if (auto EC = fs::resize_file_before_mapping_readwrite(File.FD, Size)) {
consumeError(File.discard());
return errorCodeToError(EC);
}
-#endif
// Mmap it.
std::error_code EC;
- auto MappedFile = std::make_unique<fs::mapped_file_region>(
- fs::convertFDToNativeFile(File.FD), fs::mapped_file_region::readwrite,
- Size, 0, EC);
+ fs::mapped_file_region MappedFile =
+ fs::mapped_file_region(fs::convertFDToNativeFile(File.FD),
+ fs::mapped_file_region::readwrite, Size, 0, EC);
// mmap(2) can fail if the underlying filesystem does not support it.
// If that happens, we fall back to in-memory buffer as the last resort.