Improved the speed of LoadFile() in debug mode.

Apparently, istreambuf_iterator has a lot of overhead.

Change-Id: I804f4e8f2b380b05e939edefe0e1e88cd10e920c
Tested: on Linux.
parent 782e05de
...@@ -111,8 +111,10 @@ inline bool FileExists(const char *name) { ...@@ -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();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment