[llvm-commits] [llvm] r106754 - in /llvm/trunk: include/llvm/Support/MemoryBuffer.h lib/Support/MemoryBuffer.cpp
Dan Gohman
gohman at apple.com
Thu Jun 24 09:25:51 PDT 2010
Author: djg
Date: Thu Jun 24 11:25:50 2010
New Revision: 106754
URL: http://llvm.org/viewvc/llvm-project?rev=106754&view=rev
Log:
Add overloads for getFile and getFileOrSTDIN which take a const char *
instead of a StringRef, avoiding the need to copy the string in the
common case.
Modified:
llvm/trunk/include/llvm/Support/MemoryBuffer.h
llvm/trunk/lib/Support/MemoryBuffer.cpp
Modified: llvm/trunk/include/llvm/Support/MemoryBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MemoryBuffer.h?rev=106754&r1=106753&r2=106754&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/MemoryBuffer.h (original)
+++ llvm/trunk/include/llvm/Support/MemoryBuffer.h Thu Jun 24 11:25:50 2010
@@ -67,6 +67,10 @@
std::string *ErrStr = 0,
int64_t FileSize = -1,
struct stat *FileInfo = 0);
+ static MemoryBuffer *getFile(const char *Filename,
+ std::string *ErrStr = 0,
+ int64_t FileSize = -1,
+ struct stat *FileInfo = 0);
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
/// that EndPtr[0] must be a null byte and be accessible!
@@ -105,6 +109,10 @@
std::string *ErrStr = 0,
int64_t FileSize = -1,
struct stat *FileInfo = 0);
+ static MemoryBuffer *getFileOrSTDIN(const char *Filename,
+ std::string *ErrStr = 0,
+ int64_t FileSize = -1,
+ struct stat *FileInfo = 0);
};
} // end namespace llvm
Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=106754&r1=106753&r2=106754&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Thu Jun 24 11:25:50 2010
@@ -141,6 +141,15 @@
return getFile(Filename, ErrStr, FileSize, FileInfo);
}
+MemoryBuffer *MemoryBuffer::getFileOrSTDIN(const char *Filename,
+ std::string *ErrStr,
+ int64_t FileSize,
+ struct stat *FileInfo) {
+ if (strcmp(Filename, "-") == 0)
+ return getSTDIN(ErrStr);
+ return getFile(Filename, ErrStr, FileSize, FileInfo);
+}
+
//===----------------------------------------------------------------------===//
// MemoryBuffer::getFile implementation.
//===----------------------------------------------------------------------===//
@@ -177,12 +186,17 @@
MemoryBuffer *MemoryBuffer::getFile(StringRef Filename, std::string *ErrStr,
int64_t FileSize, struct stat *FileInfo) {
- int OpenFlags = 0;
+ SmallString<256> PathBuf(Filename.begin(), Filename.end());
+ return MemoryBuffer::getFile(PathBuf.c_str(), ErrStr, FileSize, FileInfo);
+}
+
+MemoryBuffer *MemoryBuffer::getFile(const char *Filename, std::string *ErrStr,
+ int64_t FileSize, struct stat *FileInfo) {
+ int OpenFlags = O_RDONLY;
#ifdef O_BINARY
OpenFlags |= O_BINARY; // Open input file in binary mode on win32.
#endif
- SmallString<256> PathBuf(Filename.begin(), Filename.end());
- int FD = ::open(PathBuf.c_str(), O_RDONLY|OpenFlags);
+ int FD = ::open(Filename, OpenFlags);
if (FD == -1) {
if (ErrStr) *ErrStr = sys::StrError();
return 0;
More information about the llvm-commits
mailing list