Merge pull request #2473 from RichardTea/slow_xml_load

Speed up loading of XML-based formats
pull/2485/head^2
Kim Kulling 2019-06-04 15:20:20 +02:00 committed by GitHub
commit 5dcb2cb8c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 7 deletions

View File

@ -91,14 +91,15 @@ public:
stream->Read(&data[0],data.size(),1); stream->Read(&data[0],data.size(),1);
// Remove null characters from the input sequence otherwise the parsing will utterly fail // Remove null characters from the input sequence otherwise the parsing will utterly fail
unsigned int size = 0; // std::find is usually much faster than manually iterating
unsigned int size_max = static_cast<unsigned int>(data.size()); // It is very unlikely that there will be any null characters
for(unsigned int i = 0; i < size_max; i++) { auto null_char_iter = std::find(data.begin(), data.end(), '\0');
if(data[i] != '\0') {
data[size++] = data[i]; 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); BaseImporter::ConvertToUTF8(data);
} }