From 45c12cd5fb10803f359852c4866cac5031848429 Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Mon, 20 May 2019 13:49:56 +0100 Subject: [PATCH] Update irrXMLWrapper.h Use std::find to find and remove null characters from XML --- include/assimp/irrXMLWrapper.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/include/assimp/irrXMLWrapper.h b/include/assimp/irrXMLWrapper.h index ec8ee7c76..290cf67ea 100644 --- a/include/assimp/irrXMLWrapper.h +++ b/include/assimp/irrXMLWrapper.h @@ -91,14 +91,15 @@ public: stream->Read(&data[0],data.size(),1); // Remove null characters from the input sequence otherwise the parsing will utterly fail - unsigned int size = 0; - unsigned int size_max = static_cast(data.size()); - for(unsigned int i = 0; i < size_max; i++) { - if(data[i] != '\0') { - data[size++] = data[i]; - } + // std::find is usually much faster than manually iterating + // It is very unlikely that there will be any null characters + auto null_char_iter = std::find(data.begin(), data.end(), '\0'); + + while (null_char_iter != data.end()) + { + null_char_iter = data.erase(null_char_iter); + null_char_iter = std::find(null_char_iter, data.end(), '\0'); } - data.resize(size); BaseImporter::ConvertToUTF8(data); }