Remove some more allocations

This commit is contained in:
Nicolas Werner 2021-03-14 15:32:14 +01:00
parent 98e0b95635
commit 9b8e6c7f5c
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
4 changed files with 18 additions and 14 deletions

View file

@ -182,7 +182,8 @@ CommunitiesListItem::updateTooltip()
if (groupId_ == "world") if (groupId_ == "world")
setToolTip(tr("All rooms")); setToolTip(tr("All rooms"));
else if (is_tag()) { 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") if (tag == "m.favourite")
setToolTip(tr("Favourite rooms")); setToolTip(tr("Favourite rooms"));
else if (tag == "m.lowpriority") else if (tag == "m.lowpriority")

View file

@ -32,16 +32,17 @@ qmlMessageHandler(QtMsgType type, const QMessageLogContext &context, const QStri
if ( if (
// Surpress binding wrning for now, as we can't set restore mode to keep compat with // Surpress binding wrning for now, as we can't set restore mode to keep compat with
// qt 5.10 // qt 5.10
msg.contains( msg.contains(QStringLiteral(
"QML Binding: Not restoring previous value because restoreMode has not been set.") || "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 // 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 // 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 // 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! // 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. // 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 " msg.endsWith(QStringLiteral(
"deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }")) "QML Connections: Implicitly defined onFoo properties in Connections are "
"deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }")))
return; return;
switch (type) { switch (type) {

View file

@ -10,7 +10,6 @@
#include <QCache> #include <QCache>
#include <QObject> #include <QObject>
#include <QVariant> #include <QVariant>
#include <qhashfunctions.h>
#include <mtx/events/collections.hpp> #include <mtx/events/collections.hpp>
#include <mtx/responses/messages.hpp> #include <mtx/responses/messages.hpp>
@ -25,6 +24,11 @@ class EventStore : public QObject
public: public:
EventStore(std::string room_id, QObject *parent); 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 struct Index
{ {
std::string room; std::string room;
@ -32,10 +36,9 @@ public:
friend uint qHash(const Index &i, uint seed = 0) noexcept friend uint qHash(const Index &i, uint seed = 0) noexcept
{ {
QtPrivate::QHashCombine hash;
seed = seed =
hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size())); hashCombine(qHashBits(i.room.data(), (int)i.room.size(), seed), seed);
seed = hash(seed, i.idx); seed = hashCombine(qHash(i.idx, seed), seed);
return seed; return seed;
} }
@ -50,10 +53,9 @@ public:
friend uint qHash(const IdIndex &i, uint seed = 0) noexcept friend uint qHash(const IdIndex &i, uint seed = 0) noexcept
{ {
QtPrivate::QHashCombine hash;
seed = seed =
hash(seed, QByteArray::fromRawData(i.room.data(), (int)i.room.size())); hashCombine(qHashBits(i.room.data(), (int)i.room.size(), seed), seed);
seed = hash(seed, QByteArray::fromRawData(i.id.data(), (int)i.id.size())); seed = hashCombine(qHashBits(i.id.data(), (int)i.id.size(), seed), seed);
return seed; return seed;
} }

View file

@ -122,7 +122,7 @@ Avatar::setDevicePixelRatio(double ratio)
void void
Avatar::paintEvent(QPaintEvent *) 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); QPainter painter(this);