summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-03-14 15:32:14 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-03-14 15:34:18 +0100
commit9b8e6c7f5cd9de7a8c4cbd0727a1956e2b27b0d0 (patch)
tree2b72d3225f5cc12886bcb808a5a44249234484f7 /src/timeline
parentReduce allocations when escaping emoji (diff)
downloadnheko-9b8e6c7f5cd9de7a8c4cbd0727a1956e2b27b0d0.tar.xz
Remove some more allocations
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/EventStore.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h
index a10c2126..c7a7588b 100644
--- a/src/timeline/EventStore.h
+++ b/src/timeline/EventStore.h
@@ -10,7 +10,6 @@
 #include <QCache>
 #include <QObject>
 #include <QVariant>
-#include <qhashfunctions.h>
 
 #include <mtx/events/collections.hpp>
 #include <mtx/responses/messages.hpp>
@@ -25,6 +24,11 @@ class EventStore : public QObject
 public:
         EventStore(std::string room_id, QObject *parent);
 
+        // taken from QtPrivate::QHashCombine
+        static uint hashCombine(uint hash, uint seed)
+        {
+                return seed ^ (hash + 0x9e3779b9 + (seed << 6) + (seed >> 2));
+        };
         struct Index
         {
                 std::string room;
@@ -32,10 +36,9 @@ public:
 
                 friend uint qHash(const Index &i, uint seed = 0) noexcept
                 {
-                        QtPrivate::QHashCombine hash;
                         seed =
-                          hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size()));
-                        seed = hash(seed, i.idx);
+                          hashCombine(qHashBits(i.room.data(), (int)i.room.size(), seed), seed);
+                        seed = hashCombine(qHash(i.idx, seed), seed);
                         return seed;
                 }
 
@@ -50,10 +53,9 @@ public:
 
                 friend uint qHash(const IdIndex &i, uint seed = 0) noexcept
                 {
-                        QtPrivate::QHashCombine hash;
                         seed =
-                          hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size()));
-                        seed = hash(seed, QByteArray::fromRawData(i.id.data(), (int)i.id.size()));
+                          hashCombine(qHashBits(i.room.data(), (int)i.room.size(), seed), seed);
+                        seed = hashCombine(qHashBits(i.id.data(), (int)i.id.size(), seed), seed);
                         return seed;
                 }