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")
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")

View file

@ -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) {

View file

@ -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;
}

View file

@ -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);