Reimplement MemoryBuffer::getFile with three enhancements:
authorChris Lattner <sabre@nondot.org>
Tue, 1 Apr 2008 06:05:21 +0000 (06:05 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 1 Apr 2008 06:05:21 +0000 (06:05 +0000)
commit11da4cf25c3de590ecf434316973e9f25eec34c3
treed87f943e29eaabf9e204fd2ab8af186183e915e9
parent799ed1053b6a4cb2e3a6d588bd24025daee7ad1f
Reimplement MemoryBuffer::getFile with three enhancements:

1) stop using MappedFile.
2) if profitable use the sys::path::MapInFilePages api to
   read the file.
3) otherwise fallback to read.

When sys::path::MapInFilePages is implemented, this provides
several benefits:

#1: this avoids fragmenting memory for small files.
#2: this avoids extraneous stat calls when the file size is known.
#3: this only keeps the file descriptor open while reading the
    file, not for the duration of the lifetime of the memory
    buffer.  This fixes a serious clang FD 'leak' problem.

I believe that this will work on a win32 machine, but I don't have
one to test on.  I'd appreciate it if someone could check.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49031 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Support/MemoryBuffer.cpp