forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 ¬e1, const QmlNote ¬e2);
|
||||
friend bool operator!=(const QmlNote ¬e1, const QmlNote ¬e2);
|
||||
|
||||
friend QDataStream &operator>>(QDataStream &stream, QmlNote ¬e);
|
||||
friend QDataStream &operator<<(QDataStream &stream, const QmlNote ¬e);
|
||||
|
||||
private:
|
||||
int m_typeIndex;
|
||||
int m_collapsedRow;
|
||||
qint64 m_startTime;
|
||||
@@ -60,12 +63,6 @@ private:
|
||||
bool m_loaded;
|
||||
};
|
||||
|
||||
bool operator==(const QmlNote ¬e1, const QmlNote ¬e2);
|
||||
bool operator!=(const QmlNote ¬e1, const QmlNote ¬e2);
|
||||
|
||||
QDataStream &operator>>(QDataStream &stream, QmlNote ¬e);
|
||||
QDataStream &operator<<(QDataStream &stream, const QmlNote ¬e);
|
||||
|
||||
} // namespace QmlProfiler
|
||||
|
||||
Q_DECLARE_METATYPE(QmlProfiler::QmlNote)
|
||||
|
||||
Reference in New Issue
Block a user