Remove the ref-qualified versions of segments and normalized

They can't be ref-qualified if the QVersionNumber object doesn't actually
hold a QVector<int>, as the next commit will make it: for segments(),
there might not be a QVector to be moved; for normalized(), the common
case will be that there's no gain in ref-qualifying.

Change-Id: I4bfb8b8765a502c0de6aed693752217106e575a2
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Thiago Macieira 2014-09-22 15:10:53 -07:00 committed by Marc Mutz
parent 4e8adb4b7b
commit e9a7825cf7
2 changed files with 17 additions and 54 deletions

View File

@ -167,6 +167,14 @@ QT_BEGIN_NAMESPACE
\sa majorVersion(), minorVersion(), microVersion()
*/
QVector<int> QVersionNumber::segments() const
{
QVector<int> result;
result.resize(segmentCount());
for (int i = 0; i < segmentCount(); ++i)
result[i] = segmentAt(i);
return result;
}
/*!
\fn int QVersionNumber::segmentAt(int index) const
@ -195,6 +203,13 @@ QT_BEGIN_NAMESPACE
\snippet qversionnumber/main.cpp 4
*/
QVersionNumber QVersionNumber::normalized() const
{
QVector<int> segs = m_segments;
while (segs.size() && segs.last() == 0)
segs.pop_back();
return QVersionNumber(qMove(segs));
}
/*!
\fn bool QVersionNumber::isPrefixOf(const QVersionNumber &other) const
@ -404,21 +419,6 @@ QVersionNumber QVersionNumber::fromString(const QString &string, int *suffixInde
return QVersionNumber(qMove(seg));
}
/*!
\fn QVersionNumber QVersionNumber::normalizedImpl(QVector<int> &segs)
Implementation of the normalized() function. Takes the movable list \a segs
and normalizes them.
\internal
*/
QVersionNumber QVersionNumber::normalizedImpl(QVector<int> &segs)
{
while (segs.size() && segs.last() == 0)
segs.pop_back();
return QVersionNumber(qMove(segs));
}
#ifndef QT_NO_DATASTREAM
/*!
\fn QDataStream& operator<<(QDataStream &out,

View File

@ -97,44 +97,9 @@ public:
inline int microVersion() const Q_DECL_NOTHROW Q_REQUIRED_RESULT
{ return segmentAt(2); }
#if defined(Q_COMPILER_REF_QUALIFIERS)
# if defined(Q_CC_GNU)
// required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61941
# pragma push_macro("Q_REQUIRED_RESULT")
# undef Q_REQUIRED_RESULT
# define Q_REQUIRED_RESULT
# define Q_REQUIRED_RESULT_pushed
# endif
inline QVersionNumber normalized() const & Q_REQUIRED_RESULT
{
QVector<int> segs(m_segments);
return normalizedImpl(segs);
}
Q_CORE_EXPORT QVersionNumber normalized() const Q_REQUIRED_RESULT;
inline QVersionNumber normalized() && Q_REQUIRED_RESULT
{
return normalizedImpl(m_segments);
}
inline QVector<int> segments() const & Q_DECL_NOTHROW Q_REQUIRED_RESULT
{ return m_segments; }
inline QVector<int> segments() && Q_DECL_NOTHROW Q_REQUIRED_RESULT
{ return qMove(m_segments); }
# ifdef Q_REQUIRED_RESULT_pushed
# pragma pop_macro("Q_REQUIRED_RESULT")
# endif
#else
inline QVersionNumber normalized() const Q_REQUIRED_RESULT
{
QVector<int> segs(m_segments);
return normalizedImpl(segs);
}
inline QVector<int> segments() const Q_DECL_NOTHROW Q_REQUIRED_RESULT
{ return m_segments; }
#endif
Q_CORE_EXPORT QVector<int> segments() const Q_REQUIRED_RESULT;
inline int segmentAt(int index) const Q_DECL_NOTHROW Q_REQUIRED_RESULT
{ return (m_segments.size() > index) ? m_segments.at(index) : 0; }
@ -152,8 +117,6 @@ public:
Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = 0) Q_REQUIRED_RESULT;
private:
Q_CORE_EXPORT static QVersionNumber normalizedImpl(QVector<int> &segs) Q_REQUIRED_RESULT;
#ifndef QT_NO_DATASTREAM
friend Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version);
#endif