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 <edward.welbourne@qt.io>
(cherry picked from commit 205c64bd112e074920557f34bef8a3807350f7e9)
This commit is contained in:
Ivan Solovev 2024-08-29 11:50:02 +02:00
parent 759065adff
commit 5c5bedd2a6
2 changed files with 5 additions and 5 deletions

View File

@ -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;

View File

@ -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,