summary refs log tree commit diff
path: root/src
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
parentReduce allocations when escaping emoji (diff)
downloadnheko-9b8e6c7f5cd9de7a8c4cbd0727a1956e2b27b0d0.tar.xz
Remove some more allocations
Diffstat (limited to 'src')
-rw-r--r--src/CommunitiesListItem.cpp3
-rw-r--r--src/Logging.cpp11
-rw-r--r--src/timeline/EventStore.h16
-rw-r--r--src/ui/Avatar.cpp2
4 files changed, 18 insertions, 14 deletions
diff --git a/src/CommunitiesListItem.cpp b/src/CommunitiesListItem.cpp
index 3a121dc0..a2f2777d 100644
--- a/src/CommunitiesListItem.cpp
+++ b/src/CommunitiesListItem.cpp
@@ -182,7 +182,8 @@ CommunitiesListItem::updateTooltip()
         if (groupId_ == "world")
                 setToolTip(tr("All rooms"));
         else if (is_tag()) {
-                QString tag = groupId_.right(static_cast<int>(groupId_.size() - strlen("tag:")));
+                QStringRef tag =
+                  groupId_.rightRef(static_cast<int>(groupId_.size() - strlen("tag:")));
                 if (tag == "m.favourite")
                         setToolTip(tr("Favourite rooms"));
                 else if (tag == "m.lowpriority")
diff --git a/src/Logging.cpp b/src/Logging.cpp
index 436de811..642e8957 100644
--- a/src/Logging.cpp
+++ b/src/Logging.cpp
@@ -32,16 +32,17 @@ qmlMessageHandler(QtMsgType type, const QMessageLogContext &context, const QStri
         if (
           // Surpress binding wrning for now, as we can't set restore mode to keep compat with
           // qt 5.10
-          msg.contains(
-            "QML Binding: Not restoring previous value because restoreMode has not been set.") ||
+          msg.contains(QStringLiteral(
+            "QML Binding: Not restoring previous value because restoreMode has not been set.")) ||
           // The default style has the point size set. If you use pixel size anywhere, you get
           // that warning, which is useless, since sometimes you need the pixel size to match the
           // text to the size of the outer element for example. This is done in the avatar and
           // without that you get one warning for every Avatar displayed, which is stupid!
-          msg.endsWith("Both point size and pixel size set. Using pixel size.") ||
+          msg.endsWith(QStringLiteral("Both point size and pixel size set. Using pixel size.")) ||
           // The new syntax breaks rebinding on Qt < 5.15. Until we can drop that, we still need it.
-          msg.endsWith("QML Connections: Implicitly defined onFoo properties in Connections are "
-                       "deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }"))
+          msg.endsWith(QStringLiteral(
+            "QML Connections: Implicitly defined onFoo properties in Connections are "
+            "deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }")))
                 return;
 
         switch (type) {
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;
                 }
 
diff --git a/src/ui/Avatar.cpp b/src/ui/Avatar.cpp
index 53e72618..154a0e2c 100644
--- a/src/ui/Avatar.cpp
+++ b/src/ui/Avatar.cpp
@@ -122,7 +122,7 @@ Avatar::setDevicePixelRatio(double ratio)
 void
 Avatar::paintEvent(QPaintEvent *)
 {
-        bool rounded = QSettings().value("user/avatar_circles", true).toBool();
+        bool rounded = QSettings().value(QStringLiteral("user/avatar_circles"), true).toBool();
 
         QPainter painter(this);