Avoid unnecessary reallocations of the "linebuf" string

safeGetline() already clears the string buffer before writing to it, so
the same buffer can be used multiple times, but the loops calling
safeGetline() have the string scoped within the loop, so its
constructed and destructed in each loop iteration, causing lots of
unnecessary allocations.

Parse times for some large .obj files (without asan):

        File A  File B  File C
Before  2743ms   589ms   615ms
After   2500ms   573ms   545ms
This commit is contained in:
Björn Steinbrink
2016-10-24 11:28:33 +02:00
parent fed4322d26
commit ebdbd8a231

View File

@@ -692,9 +692,8 @@ void LoadMtl(std::map<std::string, int> *material_map,
material_t material;
InitMaterial(&material);
std::string linebuf;
while (inStream->peek() != -1) {
std::string linebuf;
safeGetline(*inStream, linebuf);
// Trim trailing whitespace.
@@ -1090,8 +1089,8 @@ bool LoadObj(attrib_t *attrib, std::vector<shape_t> *shapes,
shape_t shape;
std::string linebuf;
while (inStream->peek() != -1) {
std::string linebuf;
safeGetline(*inStream, linebuf);
// Trim newline '\r\n' or '\n'