[PATCH] [Support] Add MemoryBuffer::getFileSlice()

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Tue Oct 7 12:23:42 PDT 2014


I think this is a good idea. It is perfectly reasonable for a tool to know that it needs only a part of a file and let the OS unmap the rest.

I noticed some horrible inconsistencies in the pre existing code and fixed them. I should hopefully make this change a bit simpler.

================
Comment at: include/llvm/Support/MemoryBuffer.h:135
@@ +134,3 @@
+  static ErrorOr<std::unique_ptr<MemoryBuffer>>
+  getFileSlice(StringRef Filename, uint64_t Offset, uint64_t Length);
+
----------------
For consistency with getOpenFileSlice, please make this

  getFileSlice(const Twine &Filename, uint64_t MapSize,  int64_t Offset);

or update getOpenFileSlice.


================
Comment at: lib/Support/MemoryBuffer.cpp:174
@@ +173,3 @@
+  int FD;
+  std::error_code EC = sys::fs::openFileForRead(NullTermName.data(), FD);
+  if (EC)
----------------
Can't you just add an MapSize argument to getFileAux?

http://reviews.llvm.org/D5423






More information about the llvm-commits mailing list