[llvm] r263591 - [libfuzzer] speeding up corpus load
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 15 14:47:22 PDT 2016
Author: aizatsky
Date: Tue Mar 15 16:47:21 2016
New Revision: 263591
URL: http://llvm.org/viewvc/llvm-project?rev=263591&view=rev
Log:
[libfuzzer] speeding up corpus load
Modified:
llvm/trunk/lib/Fuzzer/FuzzerIO.cpp
Modified: llvm/trunk/lib/Fuzzer/FuzzerIO.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerIO.cpp?rev=263591&r1=263590&r2=263591&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerIO.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerIO.cpp Tue Mar 15 16:47:21 2016
@@ -61,14 +61,16 @@ Unit FileToVector(const std::string &Pat
Printf("No such directory: %s; exiting\n", Path.c_str());
exit(1);
}
- if (MaxSize) {
- Unit Res(MaxSize);
- T.read(reinterpret_cast<char*>(Res.data()), MaxSize);
- Res.resize(T.gcount());
- return Res;
- }
- return Unit((std::istreambuf_iterator<char>(T)),
- std::istreambuf_iterator<char>());
+
+ T.seekg(0, T.end);
+ size_t FileLen = T.tellg();
+ if (MaxSize)
+ FileLen = std::min(FileLen, MaxSize);
+
+ T.seekg(0, T.beg);
+ Unit Res(FileLen);
+ T.read(reinterpret_cast<char *>(Res.data()), FileLen);
+ return Res;
}
std::string FileToString(const std::string &Path) {
More information about the llvm-commits
mailing list