projects
/
platform
/
upstream
/
flatbuffers.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
782e05d
)
Improved the speed of LoadFile() in debug mode.
author
Wouter van Oortmerssen
<wvo@google.com>
Wed, 9 Sep 2015 19:56:23 +0000
(12:56 -0700)
committer
Wouter van Oortmerssen
<wvo@google.com>
Wed, 9 Sep 2015 19:56:23 +0000
(12:56 -0700)
Apparently, istreambuf_iterator has a lot of overhead.
Change-Id: I804f4e8f2b380b05e939edefe0e1e88cd10e920c
Tested: on Linux.
include/flatbuffers/util.h
patch
|
blob
|
history
diff --git
a/include/flatbuffers/util.h
b/include/flatbuffers/util.h
index
7d247dd
..
3951bbd
100644
(file)
--- a/
include/flatbuffers/util.h
+++ b/
include/flatbuffers/util.h
@@
-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();
}