From 5c5bedd2a64c96d1b7e762d2fd1d1e33ffe9272d Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Thu, 29 Aug 2024 11:50:02 +0200 Subject: [PATCH] QLocaleData: make static methods noexcept QLocaleData::c() simply returns a pointer to a static constexpr array, so it can be noexcept. The Q_ASSERT there simply checks internal data consistency. QLocaleData::findLocaleIndex() uses a QVarLengthArray, but the size is hardcoded at compile time, and the implementation does not add more elements, so it will never allocate. The static findLocaleIndexById() helper can be made noexcept, because we already made most of the QLocaleId methods noexcept. This allows us to make QLocaleData::findLocaleIndex() noexcept as well. Resulted from 6.8 API review, so picking to 6.8. Change-Id: Iaa9ccaa127f2ba13235b9c0f91a72048067266f5 Reviewed-by: Edward Welbourne (cherry picked from commit 205c64bd112e074920557f34bef8a3807350f7e9) --- src/corelib/text/qlocale.cpp | 6 +++--- src/corelib/text/qlocale_p.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index f72991c764d..82ea7ebc447 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -465,7 +465,7 @@ QByteArray QLocalePrivate::bcp47Name(char separator) const return m_data->id().withLikelySubtagsRemoved().name(separator); } -static qsizetype findLocaleIndexById(QLocaleId localeId) +static qsizetype findLocaleIndexById(QLocaleId localeId) noexcept { qsizetype idx = locale_index[localeId.language_id]; // If there are no locales for specified language (so we we've got the @@ -484,7 +484,7 @@ static qsizetype findLocaleIndexById(QLocaleId localeId) return -1; } -qsizetype QLocaleData::findLocaleIndex(QLocaleId lid) +qsizetype QLocaleData::findLocaleIndex(QLocaleId lid) noexcept { QLocaleId localeId = lid; QLocaleId likelyId = localeId.withLikelySubtagsAdded(); @@ -853,7 +853,7 @@ static qsizetype defaultIndex() return data - locale_data; } -const QLocaleData *QLocaleData::c() +const QLocaleData *QLocaleData::c() noexcept { Q_ASSERT(locale_index[QLocale::C] == 0); return locale_data; diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index f911551eebd..ee65076780b 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -244,8 +244,8 @@ struct QLocaleData public: // Having an index for each locale enables us to have diverse sources of // data, e.g. calendar locales, as well as the main CLDR-derived data. - [[nodiscard]] static qsizetype findLocaleIndex(QLocaleId localeId); - [[nodiscard]] static const QLocaleData *c(); + [[nodiscard]] static qsizetype findLocaleIndex(QLocaleId localeId) noexcept; + [[nodiscard]] static const QLocaleData *c() noexcept; enum DoubleForm { DFExponent = 0,