diff options
| author | Mike Aizatsky <aizatsky@chromium.org> | 2016-03-15 21:47:21 +0000 |
|---|---|---|
| committer | Mike Aizatsky <aizatsky@chromium.org> | 2016-03-15 21:47:21 +0000 |
| commit | 298516ffa97e5cc292fc3a0bfd21054fd677a354 (patch) | |
| tree | ef8cbb270df51eb6d6216be4cae5d35a0165f3f8 | |
| parent | ebecd6c54344abc15be328e2086fb46f616af083 (diff) | |
| download | bcm5719-llvm-298516ffa97e5cc292fc3a0bfd21054fd677a354.tar.gz bcm5719-llvm-298516ffa97e5cc292fc3a0bfd21054fd677a354.zip | |
[libfuzzer] speeding up corpus load
llvm-svn: 263591
| -rw-r--r-- | llvm/lib/Fuzzer/FuzzerIO.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerIO.cpp b/llvm/lib/Fuzzer/FuzzerIO.cpp index 3fa672123ed..be7759fcc91 100644 --- a/llvm/lib/Fuzzer/FuzzerIO.cpp +++ b/llvm/lib/Fuzzer/FuzzerIO.cpp @@ -61,14 +61,16 @@ Unit FileToVector(const std::string &Path, size_t MaxSize) { 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) { |

