Support: Extract sys::fs::readNativeFileToEOF() from MemoryBuffer
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 7 Dec 2021 20:42:13 +0000 (12:42 -0800)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 12 Jan 2022 02:03:58 +0000 (18:03 -0800)
commit345223a7be3c3c93a10f8453d96287a3a03b6754
tree938ef24e245f677565557f619e4fdbc0c905451b
parentb0492d92adc53ca2b6a6bae16f4fae85e5396ff2
Support: Extract sys::fs::readNativeFileToEOF() from MemoryBuffer

Extract the `readNativeFile()` loop from
`MemoryBuffer::getMemoryBufferForStream()` into `readNativeFileToEOF()`
to allow reuse. The chunk size is configurable; the default of `4*4096`
is exposed as `sys::fs::DefaultReadChunkSize` to allow sizing of
SmallVectors.

There's somewhere I'd like to read a usually-small file without overhead
of a MemoryBuffer; extracting existing logic rather than duplicating it.

Differential Revision: https://reviews.llvm.org/D115397
llvm/include/llvm/Support/FileSystem.h
llvm/lib/Support/MemoryBuffer.cpp
llvm/lib/Support/Path.cpp
llvm/unittests/Support/Path.cpp