mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 21:17:25 +00:00
Improved the speed of LoadFile() in debug mode.
Apparently, istreambuf_iterator has a lot of overhead. Change-Id: I804f4e8f2b380b05e939edefe0e1e88cd10e920c Tested: on Linux.
This commit is contained in:
@@ -111,8 +111,10 @@ inline bool FileExists(const char *name) {
|
||||
inline bool LoadFile(const char *name, bool binary, std::string *buf) {
|
||||
std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in);
|
||||
if (!ifs.is_open()) return false;
|
||||
*buf = std::string(std::istreambuf_iterator<char>(ifs),
|
||||
std::istreambuf_iterator<char>());
|
||||
ifs.seekg(0, std::ios::end);
|
||||
(*buf).resize(ifs.tellg());
|
||||
ifs.seekg(0, std::ios::beg);
|
||||
ifs.read(&(*buf)[0], (*buf).size());
|
||||
return !ifs.bad();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user