summaryrefslogtreecommitdiffstats
path: root/src/system/Qt3DSHash.h
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2020-01-20 09:05:11 +0200
committerAntti Määttä <antti.maatta@qt.io>2020-01-22 13:29:00 +0200
commitaee9f758b2fe152d95dcd7ac9776b4e0cd765d0c (patch)
tree392884eac23a7f1829b49ace65ec5e3632c2cbe8 /src/system/Qt3DSHash.h
parent88849a83a6f9ca3524cf3ba32c3a4ed7e6fabdb9 (diff)
Optimize element attribute name hashing
Task-number: QT3DS-4041 Change-Id: I64ccd129b12053b057e5e992d89a05a2bc6cd33d Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src/system/Qt3DSHash.h')
-rw-r--r--src/system/Qt3DSHash.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/system/Qt3DSHash.h b/src/system/Qt3DSHash.h
index 8baa2db..b074d9c 100644
--- a/src/system/Qt3DSHash.h
+++ b/src/system/Qt3DSHash.h
@@ -30,6 +30,7 @@
#pragma once
#include "Qt3DSConfig.h"
+#include <qstring.h>
//==============================================================================
// Namespace
@@ -77,6 +78,37 @@ public: // Static utility
return theHash;
}
+ static TStringHash HashString(const QString &inString)
+ {
+ TStringHash theHash = 0;
+ INT32 theCount = 0;
+ for (auto theChar : inString) {
+ if (theCount == HASH_LIMIT)
+ break;
+ theHash = theChar.toLatin1() + (theHash << 6) + (theHash << 16) - theHash;
+ ++theCount;
+ }
+ theHash = (theHash << 6) + (theHash << 16) - theHash;
+
+ return theHash;
+ }
+
+ static TStringHash HashString(const QString &inString, int begin, int end)
+ {
+ TStringHash theHash = 0;
+ INT32 theCount = 0;
+ for (int i = begin; i < end; ++i) {
+ if (theCount == HASH_LIMIT)
+ break;
+ theHash = inString.at(i).toLatin1() + (theHash << 6) + (theHash << 16) - theHash;
+ ++theCount;
+ }
+ theHash = (theHash << 6) + (theHash << 16) - theHash;
+
+ return theHash;
+ }
+
+
//==============================================================================
/**
* 31-bit hash with MSB set to 0
@@ -100,6 +132,11 @@ public: // Static utility
{
return HashString(inString) & 0x03ffffff;
}
+
+ static TAttributeHash HashAttribute(const QString &inString)
+ {
+ return HashString(inString) & 0x03ffffff;
+ }
};
} // namespace Q3DStudio