Update system collator when system local is default and updates

Amends commit 94de5f9b25e1816039885c765e2a5b312f7daa7e so that every
change to the default locale is reflected in an update to the default
collator used by QString::localeAwareCompare().

Although the change to the system locale does update the QLocaleData
object shared by all system locale objects, the possible change to its
collator() may imply the default collator needs an update; and the
collator backend's init() may use the language, script and territory
that's changed in setting up the revised collator, even if the QLocale
instance referenced has the same QLocaleData.

Change-Id: I957486c03c3d779fc9a2f0b889346ec13b1af868
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit df736da245bf1ea04fadffa1f5d35c37252930a4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Edward Welbourne 2023-07-19 10:58:24 +02:00 committed by Qt Cherry-pick Bot
parent 47f219c798
commit c4a7f22e3e

View File

@ -682,6 +682,7 @@ qsizetype qt_repeatCount(QStringView s)
}
Q_CONSTINIT static const QLocaleData *default_data = nullptr;
Q_CONSTINIT QBasicAtomicInt QLocalePrivate::s_generation = Q_BASIC_ATOMIC_INITIALIZER(0);
static QLocalePrivate *c_private()
{
@ -780,6 +781,10 @@ static void updateSystemPrivate()
systemLocaleData.m_script_id = res.toInt();
// Should we replace Any values based on likely sub-tags ?
// If system locale is default locale, update the default collator's generation:
if (default_data == &systemLocaleData)
QLocalePrivate::s_generation.fetchAndAddRelaxed(1);
}
#endif // !QT_NO_SYSTEMLOCALE
@ -853,7 +858,6 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l)
static constexpr qsizetype locale_data_size = q20::ssize(locale_data) - 1; // trailing guard
Q_CONSTINIT QBasicAtomicInt QLocalePrivate::s_generation = Q_BASIC_ATOMIC_INITIALIZER(0);
Q_GLOBAL_STATIC(QSharedDataPointer<QLocalePrivate>, defaultLocalePrivate,
new QLocalePrivate(defaultData(), defaultIndex()))