From 21d4e3a69df06a085643e864bb09ec5a5af4ab6a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 10 Aug 2022 18:13:32 +0200 Subject: [PATCH] Eliminate QSystemLocaleSingleton and QSystemLocale(bool) They are no longer needed. The global static will only ever be instantiated if and when the QSystemLocale stack is empty; it will then survive to the end of run-time, serving as a bottom-of-stack instance that will always be fallen back to after any other instances' lifetimes. It can thus be a local static of the only function that accesses it. Change-Id: I21a1623728b25b46da6e25db9bb973c507a39ca3 Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/corelib/text/qlocale.cpp | 20 ++++++-------------- src/corelib/text/qlocale_p.h | 3 --- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index fb21b24ada0..e8ef6901867 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -60,13 +60,6 @@ using namespace Qt::StringLiterals; #ifndef QT_NO_SYSTEMLOCALE Q_CONSTINIT static QSystemLocale *_systemLocale = nullptr; -class QSystemLocaleSingleton: public QSystemLocale -{ -public: - QSystemLocaleSingleton() : QSystemLocale(true) {} -}; - -Q_GLOBAL_STATIC(QSystemLocaleSingleton, QSystemLocale_globalSystemLocale) Q_CONSTINIT static QLocaleData systemLocaleData = {}; #endif @@ -721,12 +714,6 @@ QSystemLocale::QSystemLocale() : next(_systemLocale) systemLocaleData.m_language_id = 0; } -/*! - \internal -*/ -QSystemLocale::QSystemLocale(bool) -{ } - /*! \internal Deletes the object. @@ -750,7 +737,12 @@ static const QSystemLocale *systemLocale() { if (_systemLocale) return _systemLocale; - return QSystemLocale_globalSystemLocale(); + + // As this is only ever instantiated with _systemLocale null, it is + // necessarily the ->next-most in any chain that may subsequently develop; + // and it won't be destructed until exit()-time. + static QSystemLocale globalInstance; + return &globalInstance; } static void updateSystemPrivate() diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index fc3d221971e..b349cccc9f8 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -103,9 +103,6 @@ public: virtual QLocale fallbackLocale() const; inline qsizetype fallbackLocaleIndex() const; -private: - QSystemLocale(bool); - friend class QSystemLocaleSingleton; }; Q_DECLARE_TYPEINFO(QSystemLocale::QueryType, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QSystemLocale::CurrencyToStringArgument, Q_RELOCATABLE_TYPE);