瀏覽代碼

Merge pull request #2473 from RichardTea/slow_xml_load

Speed up loading of XML-based formats
Kim Kulling 6 年之前
父節點
當前提交
5dcb2cb8c0
共有 1 個文件被更改,包括 8 次插入7 次删除
  1. 8 7
      include/assimp/irrXMLWrapper.h

+ 8 - 7
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<unsigned int>(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);
     }