Browse Source

Fixed suboptimal performance of file checksum calculation.

Lasse Öörni 14 years ago
parent
commit
99f9d6c18a
2 changed files with 10 additions and 3 deletions
  1. 9 1
      Engine/IO/File.cpp
  2. 1 2
      Engine/Resource/XMLFile.cpp

+ 9 - 1
Engine/IO/File.cpp

@@ -26,6 +26,7 @@
 #include "FileSystem.h"
 #include "Log.h"
 #include "PackageFile.h"
+#include "Profiler.h"
 
 #include <cstdio>
 
@@ -221,12 +222,19 @@ unsigned File::GetChecksum()
     if (!handle_)
         return 0;
     
+    PROFILE(CalculateFileChecksum);
+    
     unsigned oldPos = position_;
     checksum_ = 0;
     
     Seek(0);
     while (!IsEof())
-        checksum_ = SDBMHash(checksum_, ReadUByte());
+    {
+        unsigned char block[1024];
+        unsigned readBytes = Read(block, 1024);
+        for (unsigned i = 0; i < readBytes; ++i)
+            checksum_ = SDBMHash(checksum_, block[i]);
+    }
     
     Seek(oldPos);
     return checksum_;

+ 1 - 2
Engine/Resource/XMLFile.cpp

@@ -120,8 +120,7 @@ XMLElement XMLFile::GetRoot(const String& name)
     if (root.empty())
         return XMLElement();
     
-    String rootName(root.name());
-    if (!name.Empty() && rootName != name)
+    if (!name.Empty() && name != root.name())
         return XMLElement();
     else
         return XMLElement(this, root.internal_object());