aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2011-03-17 22:18:42 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2011-03-17 22:18:42 +0000
commit9916d2ac3941513e301e39dee76a981c7caab694 (patch)
tree0d83c49ddf87b257b95d378dc8df1bb9d61d6706
parent813c9a0f19c0d27085a3ea81eb44033747007741 (diff)
Use RequiresNullTerminator to create buffers without a null terminator
instead of copying. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127835 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/MemoryBuffer.h3
-rw-r--r--lib/Support/MemoryBuffer.cpp6
-rw-r--r--tools/lto/LTOModule.cpp11
3 files changed, 8 insertions, 12 deletions
diff --git a/include/llvm/Support/MemoryBuffer.h b/include/llvm/Support/MemoryBuffer.h
index a52dc11cff..3006367a5a 100644
--- a/include/llvm/Support/MemoryBuffer.h
+++ b/include/llvm/Support/MemoryBuffer.h
@@ -81,7 +81,8 @@ public:
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
/// that InputData must be null terminated.
static MemoryBuffer *getMemBuffer(StringRef InputData,
- StringRef BufferName = "");
+ StringRef BufferName = "",
+ bool RequiresNullTerminator = true);
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
/// copying the contents and taking ownership of it. InputData does not
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index 2be0460149..63a1c54a40 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -92,8 +92,10 @@ public:
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
/// that EndPtr[0] must be a null byte and be accessible!
MemoryBuffer *MemoryBuffer::getMemBuffer(StringRef InputData,
- StringRef BufferName) {
- return GetNamedBuffer<MemoryBufferMem>(InputData, BufferName, true);
+ StringRef BufferName,
+ bool RequiresNullTerminator) {
+ return GetNamedBuffer<MemoryBufferMem>(InputData, BufferName,
+ RequiresNullTerminator);
}
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp
index 9de3d5ffce..310e647b1f 100644
--- a/tools/lto/LTOModule.cpp
+++ b/tools/lto/LTOModule.cpp
@@ -114,18 +114,11 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
return makeLTOModule(buffer.get(), errMsg);
}
-/// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
-/// requires the byte past end of the buffer to be a zero. We might get lucky
-/// and already be that way, otherwise make a copy. Also if next byte is on a
-/// different page, don't assume it is readable.
+/// makeBuffer - Create a MemoryBuffer from a memory range.
MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
const char *startPtr = (char*)mem;
const char *endPtr = startPtr+length;
- if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
- *endPtr != 0)
- return MemoryBuffer::getMemBufferCopy(StringRef(startPtr, length));
-
- return MemoryBuffer::getMemBuffer(StringRef(startPtr, length));
+ return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false);
}