forked from OSchip/llvm-project
Use RequiresNullTerminator to create buffers without a null terminator
instead of copying. llvm-svn: 127835
This commit is contained in:
parent
aad34d882d
commit
ab959a2e68
|
@ -81,7 +81,8 @@ public:
|
||||||
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
|
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
|
||||||
/// that InputData must be null terminated.
|
/// that InputData must be null terminated.
|
||||||
static MemoryBuffer *getMemBuffer(StringRef InputData,
|
static MemoryBuffer *getMemBuffer(StringRef InputData,
|
||||||
StringRef BufferName = "");
|
StringRef BufferName = "",
|
||||||
|
bool RequiresNullTerminator = true);
|
||||||
|
|
||||||
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
|
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
|
||||||
/// copying the contents and taking ownership of it. InputData does not
|
/// copying the contents and taking ownership of it. InputData does not
|
||||||
|
|
|
@ -92,8 +92,10 @@ public:
|
||||||
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
|
/// getMemBuffer - Open the specified memory range as a MemoryBuffer. Note
|
||||||
/// that EndPtr[0] must be a null byte and be accessible!
|
/// that EndPtr[0] must be a null byte and be accessible!
|
||||||
MemoryBuffer *MemoryBuffer::getMemBuffer(StringRef InputData,
|
MemoryBuffer *MemoryBuffer::getMemBuffer(StringRef InputData,
|
||||||
StringRef BufferName) {
|
StringRef BufferName,
|
||||||
return GetNamedBuffer<MemoryBufferMem>(InputData, BufferName, true);
|
bool RequiresNullTerminator) {
|
||||||
|
return GetNamedBuffer<MemoryBufferMem>(InputData, BufferName,
|
||||||
|
RequiresNullTerminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
|
/// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
|
||||||
|
|
|
@ -114,18 +114,11 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
|
||||||
return makeLTOModule(buffer.get(), errMsg);
|
return makeLTOModule(buffer.get(), errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// makeBuffer - Create a MemoryBuffer from a memory range. MemoryBuffer
|
/// makeBuffer - Create a MemoryBuffer from a memory range.
|
||||||
/// 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.
|
|
||||||
MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
|
MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) {
|
||||||
const char *startPtr = (char*)mem;
|
const char *startPtr = (char*)mem;
|
||||||
const char *endPtr = startPtr+length;
|
const char *endPtr = startPtr+length;
|
||||||
if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
|
return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false);
|
||||||
*endPtr != 0)
|
|
||||||
return MemoryBuffer::getMemBufferCopy(StringRef(startPtr, length));
|
|
||||||
|
|
||||||
return MemoryBuffer::getMemBuffer(StringRef(startPtr, length));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue