summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-23 20:25:01 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-23 20:25:01 +0000
commit3d2ac2e41a96f1989a4aa240b8323d09e5cdd397 (patch)
tree9290fa7a4deb8af7aa0cee250e301312ac6f7a84 /llvm/lib
parent03085c71848efe4b3308d87a345852ce554237d7 (diff)
downloadbcm5719-llvm-3d2ac2e41a96f1989a4aa240b8323d09e5cdd397.tar.gz
bcm5719-llvm-3d2ac2e41a96f1989a4aa240b8323d09e5cdd397.zip
Split getOpenFile into getOpenFile and getOpenFileSlice.
The main observation is that we never need both the filesize and the map size. When mapping a slice of a file, it doesn't make sense to request a null terminator and that would be the only case where the filesize would be used. There are other cleanups that should be done in this area: * A client should not have to pass the size (even an explicit -1) to say if it wants a null terminator or not, so we should probably swap the argument order. * The default should be to not require a null terminator. Very few clients require this, but many end up asking for it just because it is the default. llvm-svn: 186984
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/MemoryBuffer.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 051d64b0386..cab45c736b5 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -248,6 +248,11 @@ error_code MemoryBuffer::getFile(StringRef Filename,
RequiresNullTerminator);
}
+static error_code getOpenFileImpl(int FD, const char *Filename,
+ OwningPtr<MemoryBuffer> &Result,
+ uint64_t FileSize, uint64_t MapSize,
+ int64_t Offset, bool RequiresNullTerminator);
+
error_code MemoryBuffer::getFile(const char *Filename,
OwningPtr<MemoryBuffer> &result,
int64_t FileSize,
@@ -257,8 +262,8 @@ error_code MemoryBuffer::getFile(const char *Filename,
if (EC)
return EC;
- error_code ret = getOpenFile(FD, Filename, result, FileSize, FileSize,
- 0, RequiresNullTerminator);
+ error_code ret = getOpenFileImpl(FD, Filename, result, FileSize, FileSize, 0,
+ RequiresNullTerminator);
close(FD);
return ret;
}
@@ -305,11 +310,10 @@ static bool shouldUseMmap(int FD,
return true;
}
-error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
- OwningPtr<MemoryBuffer> &result,
- uint64_t FileSize, uint64_t MapSize,
- int64_t Offset,
- bool RequiresNullTerminator) {
+static error_code getOpenFileImpl(int FD, const char *Filename,
+ OwningPtr<MemoryBuffer> &result,
+ uint64_t FileSize, uint64_t MapSize,
+ int64_t Offset, bool RequiresNullTerminator) {
static int PageSize = sys::process::get_self()->page_size();
// Default is to map the full file.
@@ -386,6 +390,20 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
return error_code::success();
}
+error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
+ OwningPtr<MemoryBuffer> &Result,
+ uint64_t FileSize,
+ bool RequiresNullTerminator) {
+ return getOpenFileImpl(FD, Filename, Result, FileSize, FileSize, 0,
+ RequiresNullTerminator);
+}
+
+error_code MemoryBuffer::getOpenFileSlice(int FD, const char *Filename,
+ OwningPtr<MemoryBuffer> &Result,
+ uint64_t MapSize, int64_t Offset) {
+ return getOpenFileImpl(FD, Filename, Result, -1, MapSize, Offset, false);
+}
+
//===----------------------------------------------------------------------===//
// MemoryBuffer::getSTDIN implementation.
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud