- std::unique_ptr<mapped_file_region> MappedFile(new mapped_file_region(
- FD, true, mapped_file_region::readwrite, Size, 0, EC));
+ sys::RemoveFileOnSignal(TempFilePath);
+
+#ifndef LLVM_ON_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.
+ EC = sys::fs::resize_file(FD, Size);