QCollator: port compare(ptr, n, ptr, n) to qsizetype

While the function is inline, the class is exported wholesale, so the
function forms part of the ABI on Windows (but not Unix), so we must
overload, can't replace.

To avoid ambiguities where users pass different integer types as the
lengths of the LHS and RHS strings, QT_REMOVED_SINCE the old overload.

Since the removed function has an inline definition, it suffices to
just include the header into the corresponding QT_REMOVED_SINCE
section of the removed_api.cpp file, to elegantly solve the BiC
problem only for those platforms (MSVC) where it matters.

Task-number: QTBUG-103531
Change-Id: I74d446f08fcd6247a2ec44575b8afef8d014c3b5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 749b2df889ac94c106e59b915ec5862384978878)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-07-18 10:46:16 +02:00 committed by Qt Cherry-pick Bot
parent 21c1b8606f
commit 2e1699d3b0
3 changed files with 10 additions and 1 deletions

View File

@ -169,6 +169,8 @@ QCalendar::QCalendar(QStringView name)
QCalendar::QCalendar(QLatin1StringView name)
: QCalendar(QAnyStringView{name}) {}
#include "qcollator.h" // inline function compare(ptr, n, ptr, n) (for MSVC)
#if QT_CONFIG(future)
#include "qfutureinterface.h"

View File

@ -318,7 +318,7 @@ bool QCollator::ignorePunctuation() const
*/
/*!
\fn int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const
\fn int QCollator::compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const
\overload
\since 5.2
@ -327,6 +327,9 @@ bool QCollator::ignorePunctuation() const
Returns an integer less than, equal to, or greater than zero depending on
whether \a s1 sorts before, with or after \a s2.
\note In Qt versions prior to 6.4, the length arguments were of type
\c{int}, not \c{qsizetype}.
*/
#endif // QT_STRINGVIEW_LEVEL < 2

View File

@ -68,8 +68,12 @@ public:
#if QT_STRINGVIEW_LEVEL < 2
int compare(const QString &s1, const QString &s2) const
{ return compare(QStringView(s1), QStringView(s2)); }
#if QT_CORE_REMOVED_SINCE(6, 4) && QT_POINTER_SIZE != 4
int compare(const QChar *s1, int len1, const QChar *s2, int len2) const
{ return compare(QStringView(s1, len1), QStringView(s2, len2)); }
#endif
int compare(const QChar *s1, qsizetype len1, const QChar *s2, qsizetype len2) const
{ return compare(QStringView(s1, len1), QStringView(s2, len2)); }
bool operator()(const QString &s1, const QString &s2) const
{ return compare(s1, s2) < 0; }