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:
Wouter van Oortmerssen 2015-09-09 12:56:23 -07:00
parent 782e05de55
commit 01e06b69a5
1 changed files with 4 additions and 2 deletions

View File

@ -111,8 +111,10 @@ inline bool FileExists(const char *name) {
inline bool LoadFile(const char *name, bool binary, std::string *buf) { inline bool LoadFile(const char *name, bool binary, std::string *buf) {
std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in); std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in);
if (!ifs.is_open()) return false; if (!ifs.is_open()) return false;
*buf = std::string(std::istreambuf_iterator<char>(ifs), ifs.seekg(0, std::ios::end);
std::istreambuf_iterator<char>()); (*buf).resize(ifs.tellg());
ifs.seekg(0, std::ios::beg);
ifs.read(&(*buf)[0], (*buf).size());
return !ifs.bad(); return !ifs.bad();
} }