Support: Extract fs::resize_file_before_mapping_readwrite from FileOutputBuffer
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 27 Jan 2021 00:01:36 +0000 (16:01 -0800)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 8 Apr 2021 23:26:35 +0000 (16:26 -0700)
commit429088b9e214b2f39f6063a6b3639560fc7db47b
treebe73669c2b9eb26017bf129158980fa1c8bbac3f
parent38b106f6815716db4757a813d28ba4649d083c14
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
llvm/include/llvm/Support/FileSystem.h
llvm/lib/Support/FileOutputBuffer.cpp
llvm/unittests/Support/Path.cpp