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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user