aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-01-26 16:01:36 -0800
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-04-08 16:26:35 -0700
commit429088b9e214b2f39f6063a6b3639560fc7db47b (patch)
treebe73669c2b9eb26017bf129158980fa1c8bbac3f /llvm/lib/Support/FileOutputBuffer.cpp
parent38b106f6815716db4757a813d28ba4649d083c14 (diff)
downloadllvm-429088b9e214b2f39f6063a6b3639560fc7db47b.zip
llvm-429088b9e214b2f39f6063a6b3639560fc7db47b.tar.gz
llvm-429088b9e214b2f39f6063a6b3639560fc7db47b.tar.bz2
Support: Extract fs::resize_file_before_mapping_readwrite from FileOutputBuffer
Add a variant of `fs::resize_file` for use immediately before opening a file with `mapped_file_region::readwrite`. On Windows, `_chsize` (`ftruncate`) is slow, but `CreateFileMapping` (`mmap`) automatically extends the file so the call to `fs::resize_file` can be skipped. This optimization was added to `FileOutputBuffer` in da9bc2e56d5a5c6332a9def1a0065eb399182b93; this commit just extracts the logic out and adds a unit test. Differential Revision: https://reviews.llvm.org/D95490
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp9
1 files changed, 1 insertions, 8 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index 3342682..6d21258 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -132,17 +132,10 @@ 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;