From ebd5180a8fa15979119cb497e05c318cda4a9137 Mon Sep 17 00:00:00 2001 From: Martin Schultz Date: Fri, 11 Sep 2015 14:47:02 +0200 Subject: [PATCH] * made OBJReader reuse stringstream objects. Should speedup Reading on MS Windows especially with lots of materials. --- src/OpenMesh/Core/IO/reader/OBJReader.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/OpenMesh/Core/IO/reader/OBJReader.cc b/src/OpenMesh/Core/IO/reader/OBJReader.cc index cc390245..7c8803fc 100644 --- a/src/OpenMesh/Core/IO/reader/OBJReader.cc +++ b/src/OpenMesh/Core/IO/reader/OBJReader.cc @@ -172,6 +172,8 @@ read_material(std::fstream& _in) std::string keyWrd; std::string textureName; + static std::stringstream stream; + std::string key; Material mat; float f1,f2,f3; @@ -193,7 +195,8 @@ read_material(std::fstream& _in) if ( line.empty() ) continue; - std::stringstream stream(line); + stream.str(line); + stream.clear(); stream >> keyWrd; @@ -305,6 +308,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt) std::string matname; + static std::stringstream stream, lineData, tmp; + // Options supplied by the user Options userOptions = _opt; @@ -329,7 +334,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt) continue; } - std::stringstream stream(line); + stream.str(line); + stream.clear(); stream >> keyWrd; @@ -463,7 +469,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt) // read full line after detecting a face std::string faceLine; std::getline(stream,faceLine); - std::stringstream lineData( faceLine ); + lineData.str( faceLine ); + lineData.clear(); FaceHandle fh; BaseImporter::VHandles faceVertices; @@ -484,7 +491,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt) if( found != std::string::npos ){ // read the index value - std::stringstream tmp( vertex.substr(0,found) ); + tmp.str( vertex.substr(0,found) ); + tmp.clear(); // If we get an empty string this property is undefined in the file if ( vertex.substr(0,found).empty() ) { @@ -507,7 +515,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt) } else { // last component of the vertex, read it. - std::stringstream tmp( vertex ); + tmp.str( vertex ); + tmp.clear(); tmp >> value; // Clear vertex after finished reading the line