From 8b4e066ca57880c7acff8eecbeebd138e8d2e319 Mon Sep 17 00:00:00 2001 From: Amit Cirt Date: Mon, 1 May 2017 16:32:49 +0300 Subject: [PATCH] Improve performance of obj line break --- code/ObjFileParser.cpp | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 3b058f677..4b0918895 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -99,27 +99,24 @@ ObjFile::Model *ObjFileParser::GetModel() const { } void ignoreNewLines(IOStreamBuffer &streamBuffer, std::vector &buffer) { - std::vector buf(buffer); - auto copyPosition = buffer.begin(); - auto curPosition = buf.cbegin(); - do - { - while (*curPosition != '\n'&&*curPosition != '\\') - { - ++curPosition; - } - if (*curPosition == '\\') - { - copyPosition = std::copy(buf.cbegin(), curPosition, copyPosition); - *(copyPosition++) = ' '; - do - { - streamBuffer.getNextLine(buf); - } while (buf[0] == '\n'); - curPosition = buf.cbegin(); - } - } while (*curPosition != '\n'); - std::copy(buf.cbegin(), curPosition, copyPosition); + static std::vector tempBuf; + auto curPosition = buffer.begin(); + do + { + while (*curPosition!='\n'&&*curPosition!='\\') + { + ++curPosition; + } + if (*curPosition=='\\') + { + do + { + streamBuffer.getNextLine(tempBuf); + } while (tempBuf[0]=='\n'); + *curPosition = ' '; + std::copy(tempBuf.cbegin(), tempBuf.cend(), ++curPosition); + } + } while (*curPosition!='\n'); } // ------------------------------------------------------------------- // File parsing method.