From 3c1f7b615c03e55f8aaee14a5793c917c050b373 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 1 Apr 2008 06:06:37 +0000 Subject: [PATCH] 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 --- lib/Basic/SourceManager.cpp | 63 ++----------------------------------- 1 file 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 -#include -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include -#include -#else -#include -#endif -#include - -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(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; -- 2.40.0