diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-01 06:06:37 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-01 06:06:37 +0000 |
commit | 3c1f7b615c03e55f8aaee14a5793c917c050b373 (patch) | |
tree | 4516a74eaf9700bfe3fc0fa220f5a110705b3994 /lib/Basic/SourceManager.cpp | |
parent | 33bd942e7449f044ce6a9c81a008407dce4215da (diff) |
MemoryBuffer::getFile got smarter, obviating the need for readfilefast.
The new MemoryBuffer doesn't "leak" file descriptors and handles the
small file case efficiently.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49032 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/SourceManager.cpp')
-rw-r--r-- | lib/Basic/SourceManager.cpp | 63 |
1 files changed, 3 insertions, 60 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 1141bed197..42ebe29ffc 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -31,65 +31,6 @@ ContentCache::~ContentCache() { delete [] SourceLineCache; } -// FIXME: REMOVE THESE -#include <unistd.h> -#include <sys/types.h> -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include <sys/uio.h> -#include <sys/fcntl.h> -#else -#include <io.h> -#endif -#include <cerrno> - -static const MemoryBuffer *ReadFileFast(const FileEntry *FileEnt) { -#if 0 - // FIXME: Reintroduce this and zap this function once the common llvm stuff - // is fast for the small case. - return MemoryBuffer::getFile(FileEnt->getName(), strlen(FileEnt->getName()), - FileEnt->getSize()); -#endif - - // If the file is larger than some threshold, use 'read', otherwise use mmap. - if (FileEnt->getSize() >= 4096*12) - return MemoryBuffer::getFile(FileEnt->getName(), strlen(FileEnt->getName()), - 0, FileEnt->getSize()); - - MemoryBuffer *SB = MemoryBuffer::getNewUninitMemBuffer(FileEnt->getSize(), - FileEnt->getName()); - char *BufPtr = const_cast<char*>(SB->getBufferStart()); - -#if defined(LLVM_ON_WIN32) - int FD = ::open(FileEnt->getName(), O_RDONLY|O_BINARY); -#else - int FD = ::open(FileEnt->getName(), O_RDONLY); -#endif - if (FD == -1) { - delete SB; - return 0; - } - - unsigned BytesLeft = FileEnt->getSize(); - while (BytesLeft) { - ssize_t NumRead = ::read(FD, BufPtr, BytesLeft); - if (NumRead != -1) { - BytesLeft -= NumRead; - BufPtr += NumRead; - } else if (errno == EINTR) { - // try again - } else { - // error reading. - close(FD); - delete SB; - return 0; - } - } - close(FD); - - return SB; -} - - /// getFileInfo - Create or return a cached FileInfo for the specified file. /// const ContentCache* SourceManager::getContentCache(const FileEntry *FileEnt) { @@ -103,7 +44,9 @@ const ContentCache* SourceManager::getContentCache(const FileEntry *FileEnt) { return &*I; // Nope, get information. - const MemoryBuffer *File = ReadFileFast(FileEnt); + const MemoryBuffer *File = + MemoryBuffer::getFile(FileEnt->getName(), strlen(FileEnt->getName()), 0, + FileEnt->getSize()); if (File == 0) return 0; |