diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2021-01-26 16:01:36 -0800 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2021-04-08 16:26:35 -0700 |
commit | 429088b9e214b2f39f6063a6b3639560fc7db47b (patch) | |
tree | be73669c2b9eb26017bf129158980fa1c8bbac3f /llvm/lib/Support/FileOutputBuffer.cpp | |
parent | 38b106f6815716db4757a813d28ba4649d083c14 (diff) | |
download | llvm-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.cpp | 9 |
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; |