Make some qHash and comparison operators overloads hidden friends

Restricts lookup scope more to necessary bits.

Change-Id: Ia42c95aaa70534843b7f6a90bfc56d2a1202c612
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2021-12-06 05:11:04 +01:00
parent 8cb5c3cfdd
commit 104ea4accc
75 changed files with 461 additions and 518 deletions

View File

@@ -55,6 +55,26 @@ public:
int line() const { return m_line; }
int column() const { return m_column; }
friend bool operator==(const QmlEventLocation &location1, const QmlEventLocation &location2)
{
// compare filename last as it's expensive.
return location1.line() == location2.line() && location1.column() == location2.column()
&& location1.filename() == location2.filename();
}
friend bool operator!=(const QmlEventLocation &location1, const QmlEventLocation &location2)
{
return !(location1 == location2);
}
friend auto qHash(const QmlEventLocation &location)
{
return qHash(location.filename())
^ ((location.line() & 0xfff) // 12 bits of line number
| ((location.column() << 16) & 0xff0000)); // 8 bits of column
}
private:
friend QDataStream &operator>>(QDataStream &stream, QmlEventLocation &location);
friend QDataStream &operator<<(QDataStream &stream, const QmlEventLocation &location);
@@ -64,29 +84,6 @@ private:
int m_column = -1;
};
inline bool operator==(const QmlEventLocation &location1, const QmlEventLocation &location2)
{
// compare filename last as it's expensive.
return location1.line() == location2.line() && location1.column() == location2.column()
&& location1.filename() == location2.filename();
}
inline bool operator!=(const QmlEventLocation &location1, const QmlEventLocation &location2)
{
return !(location1 == location2);
}
inline auto qHash(const QmlEventLocation &location)
{
return qHash(location.filename())
^ ((location.line() & 0xfff) // 12 bits of line number
| ((location.column() << 16) & 0xff0000)); // 8 bits of column
}
QDataStream &operator>>(QDataStream &stream, QmlEventLocation &location);
QDataStream &operator<<(QDataStream &stream, const QmlEventLocation &location);
} // namespace QmlProfiler
QT_BEGIN_NAMESPACE

View File

@@ -63,9 +63,6 @@ private:
int m_detailType; // can be EventType, BindingType, PixmapEventType or SceneGraphFrameType
};
QDataStream &operator>>(QDataStream &stream, QmlEventType &type);
QDataStream &operator<<(QDataStream &stream, const QmlEventType &type);
} // namespace QmlProfiler
Q_DECLARE_METATYPE(QmlProfiler::QmlEventType)

View File

@@ -48,10 +48,13 @@ public:
void setText(const QString &text) { m_text = text; }
void setLoaded(bool loaded) { m_loaded = loaded; }
private:
friend bool operator==(const QmlNote &note1, const QmlNote &note2);
friend bool operator!=(const QmlNote &note1, const QmlNote &note2);
friend QDataStream &operator>>(QDataStream &stream, QmlNote &note);
friend QDataStream &operator<<(QDataStream &stream, const QmlNote &note);
private:
int m_typeIndex;
int m_collapsedRow;
qint64 m_startTime;
@@ -60,12 +63,6 @@ private:
bool m_loaded;
};
bool operator==(const QmlNote &note1, const QmlNote &note2);
bool operator!=(const QmlNote &note1, const QmlNote &note2);
QDataStream &operator>>(QDataStream &stream, QmlNote &note);
QDataStream &operator<<(QDataStream &stream, const QmlNote &note);
} // namespace QmlProfiler
Q_DECLARE_METATYPE(QmlProfiler::QmlNote)