From 34a095848d946d11d367ff9fcbfc26b6b26c7507 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 13 Aug 2020 15:24:50 +0200 Subject: [PATCH] Inline QString's conversions to integral types, except long long ones As requested by a ### Qt6 comment. Task-number: QTBUG-85700 Change-Id: I7c2813c0d8fbc38bcd2f7229de3a9d8e1b8b1f03 Reviewed-by: Thiago Macieira --- src/corelib/text/qstring.cpp | 38 ++++++------------------------------ src/corelib/text/qstring.h | 19 +++++++++++------- 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 24859b6e7af..d0fc3e071fe 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -6678,11 +6678,6 @@ qulonglong QString::toIntegral_helper(QStringView string, bool *ok, uint base) \sa number(), toULong(), toInt(), QLocale::toInt() */ -long QString::toLong(bool *ok, int base) const -{ - return toIntegral_helper(*this, ok, base); -} - /*! \fn ulong QString::toULong(bool *ok, int base) const @@ -6709,13 +6704,8 @@ long QString::toLong(bool *ok, int base) const \sa number(), QLocale::toUInt() */ -ulong QString::toULong(bool *ok, int base) const -{ - return toIntegral_helper(*this, ok, base); -} - - /*! + \fn int QString::toInt(bool *ok, int base) const Returns the string converted to an \c int using base \a base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails. @@ -6739,12 +6729,8 @@ ulong QString::toULong(bool *ok, int base) const \sa number(), toUInt(), toDouble(), QLocale::toInt() */ -int QString::toInt(bool *ok, int base) const -{ - return toIntegral_helper(*this, ok, base); -} - /*! + \fn uint QString::toUInt(bool *ok, int base) const Returns the string converted to an \c{unsigned int} using base \a base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails. @@ -6768,12 +6754,9 @@ int QString::toInt(bool *ok, int base) const \sa number(), toInt(), QLocale::toUInt() */ -uint QString::toUInt(bool *ok, int base) const -{ - return toIntegral_helper(*this, ok, base); -} - /*! + \fn short QString::toShort(bool *ok, int base) const + Returns the string converted to a \c short using base \a base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails. @@ -6797,12 +6780,9 @@ uint QString::toUInt(bool *ok, int base) const \sa number(), toUShort(), toInt(), QLocale::toShort() */ -short QString::toShort(bool *ok, int base) const -{ - return toIntegral_helper(*this, ok, base); -} - /*! + \fn ushort QString::toUShort(bool *ok, int base) const + Returns the string converted to an \c{unsigned short} using base \a base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails. @@ -6826,12 +6806,6 @@ short QString::toShort(bool *ok, int base) const \sa number(), toShort(), QLocale::toUShort() */ -ushort QString::toUShort(bool *ok, int base) const -{ - return toIntegral_helper(*this, ok, base); -} - - /*! Returns the string converted to a \c double value. diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 6456c088bb9..a8a1211ff57 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -712,13 +712,18 @@ public: static int localeAwareCompare(QStringView s1, QStringView s2); - // ### Qt6: make inline except for the long long versions - short toShort(bool *ok=nullptr, int base=10) const; - ushort toUShort(bool *ok=nullptr, int base=10) const; - int toInt(bool *ok=nullptr, int base=10) const; - uint toUInt(bool *ok=nullptr, int base=10) const; - long toLong(bool *ok=nullptr, int base=10) const; - ulong toULong(bool *ok=nullptr, int base=10) const; + short toShort(bool *ok=nullptr, int base=10) const + { return toIntegral_helper(*this, ok, base); } + ushort toUShort(bool *ok=nullptr, int base=10) const + { return toIntegral_helper(*this, ok, base); } + int toInt(bool *ok=nullptr, int base=10) const + { return toIntegral_helper(*this, ok, base); } + uint toUInt(bool *ok=nullptr, int base=10) const + { return toIntegral_helper(*this, ok, base); } + long toLong(bool *ok=nullptr, int base=10) const + { return toIntegral_helper(*this, ok, base); } + ulong toULong(bool *ok=nullptr, int base=10) const + { return toIntegral_helper(*this, ok, base); } qlonglong toLongLong(bool *ok=nullptr, int base=10) const; qulonglong toULongLong(bool *ok=nullptr, int base=10) const; float toFloat(bool *ok=nullptr) const;