From e9a7825cf7e5f479f7a04a5800edb752132b1070 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 22 Sep 2014 15:10:53 -0700 Subject: 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, 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 --- src/corelib/tools/qversionnumber.cpp | 30 ++++++++++++------------- src/corelib/tools/qversionnumber.h | 43 +++--------------------------------- 2 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp index 7e87d3e1d3..4bc94c25be 100644 --- a/src/corelib/tools/qversionnumber.cpp +++ b/src/corelib/tools/qversionnumber.cpp @@ -167,6 +167,14 @@ QT_BEGIN_NAMESPACE \sa majorVersion(), minorVersion(), microVersion() */ +QVector QVersionNumber::segments() const +{ + QVector 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 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 &segs) - - Implementation of the normalized() function. Takes the movable list \a segs - and normalizes them. - - \internal - */ -QVersionNumber QVersionNumber::normalizedImpl(QVector &segs) -{ - while (segs.size() && segs.last() == 0) - segs.pop_back(); - return QVersionNumber(qMove(segs)); -} - #ifndef QT_NO_DATASTREAM /*! \fn QDataStream& operator<<(QDataStream &out, diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index 449445cac6..050e685f03 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -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 segs(m_segments); - return normalizedImpl(segs); - } - - inline QVersionNumber normalized() && Q_REQUIRED_RESULT - { - return normalizedImpl(m_segments); - } - - inline QVector segments() const & Q_DECL_NOTHROW Q_REQUIRED_RESULT - { return m_segments; } - - inline QVector 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 segs(m_segments); - return normalizedImpl(segs); - } - - inline QVector segments() const Q_DECL_NOTHROW Q_REQUIRED_RESULT - { return m_segments; } -#endif + Q_CORE_EXPORT QVersionNumber normalized() const Q_REQUIRED_RESULT; + + Q_CORE_EXPORT QVector 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 &segs) Q_REQUIRED_RESULT; - #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream& operator>>(QDataStream &in, QVersionNumber &version); #endif -- cgit v1.2.3