Replace QLocalePriave::create() with a plain constructor
Be up front about using new in all the places where it's created. Made one of the global statics into a function-local static. Eliminated a static made redundant by its const sibling. Made two members const now that they can be. Change-Id: I46532b3c1e0e62d1f8c84f55494f70cff09d4404 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
e330a9bb44
commit
b83b990659
@ -583,16 +583,10 @@ static const QLocaleData *default_data = nullptr;
|
||||
static const QLocaleData *const c_data = locale_data;
|
||||
static QLocalePrivate *c_private()
|
||||
{
|
||||
static QLocalePrivate c_locale{
|
||||
c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0, QLocale::OmitGroupSeparator };
|
||||
static QLocalePrivate c_locale(c_data, 0, QLocale::OmitGroupSeparator, 1);
|
||||
return &c_locale;
|
||||
}
|
||||
|
||||
static const QLocaleData *systemData();
|
||||
static uint defaultIndex();
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QExplicitlySharedDataPointer<QLocalePrivate>, systemLocalePrivate,
|
||||
(QLocalePrivate::create(systemData(), defaultIndex())))
|
||||
|
||||
#ifndef QT_NO_SYSTEMLOCALE
|
||||
/******************************************************************************
|
||||
** Default system locale behavior
|
||||
@ -743,7 +737,7 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l)
|
||||
static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1;
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, defaultLocalePrivate,
|
||||
(QLocalePrivate::create(defaultData(), defaultIndex())))
|
||||
(new QLocalePrivate(defaultData(), defaultIndex())))
|
||||
|
||||
static QLocalePrivate *localePrivateByName(const QString &name)
|
||||
{
|
||||
@ -751,9 +745,9 @@ static QLocalePrivate *localePrivateByName(const QString &name)
|
||||
return c_private();
|
||||
const int index = QLocaleData::findLocaleIndex(QLocaleId::fromName(name));
|
||||
Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1);
|
||||
return QLocalePrivate::create(locale_data + index, index,
|
||||
locale_data[index].m_language_id == QLocale::C
|
||||
? QLocale::OmitGroupSeparator : QLocale::DefaultNumberOptions);
|
||||
return new QLocalePrivate(locale_data + index, index,
|
||||
locale_data[index].m_language_id == QLocale::C
|
||||
? QLocale::OmitGroupSeparator : QLocale::DefaultNumberOptions);
|
||||
}
|
||||
|
||||
static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script,
|
||||
@ -775,7 +769,7 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
|
||||
data = defaultData();
|
||||
index = defaultIndex();
|
||||
}
|
||||
return QLocalePrivate::create(data, index, numberOptions);
|
||||
return new QLocalePrivate(data, index, numberOptions);
|
||||
}
|
||||
|
||||
QString QLocaleData::decimalPoint() const
|
||||
@ -2442,10 +2436,10 @@ QString QLocale::toString(double i, char f, int prec) const
|
||||
|
||||
QLocale QLocale::system()
|
||||
{
|
||||
static QLocalePrivate locale(systemData(), defaultIndex(), DefaultNumberOptions, 1);
|
||||
QT_PREPEND_NAMESPACE(systemData)(); // trigger updating of the system data if necessary
|
||||
if (systemLocalePrivate.isDestroyed())
|
||||
return QLocale(QLocale::C);
|
||||
return QLocale(*systemLocalePrivate->data());
|
||||
|
||||
return QLocale(locale);
|
||||
}
|
||||
|
||||
|
||||
@ -2484,7 +2478,7 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language,
|
||||
const QLocaleId id = locale_data[index].id();
|
||||
if (filter.acceptScriptCountry(id)) {
|
||||
result.append(QLocale(*(id.language_id == C ? c_private()
|
||||
: QLocalePrivate::create(locale_data + index, index))));
|
||||
: new QLocalePrivate(locale_data + index, index))));
|
||||
}
|
||||
++index;
|
||||
} while (filter.acceptLanguage(locale_data[index].m_language_id));
|
||||
|
@ -391,23 +391,14 @@ public:
|
||||
quint8 m_grouping_least : 3; // Number of digits after last grouping separator (before decimal).
|
||||
};
|
||||
|
||||
class Q_CORE_EXPORT QLocalePrivate // A POD type
|
||||
class Q_CORE_EXPORT QLocalePrivate
|
||||
{
|
||||
public:
|
||||
static QLocalePrivate *create(
|
||||
const QLocaleData *data, const uint index,
|
||||
QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions)
|
||||
{
|
||||
auto *retval = new QLocalePrivate;
|
||||
retval->m_data = data;
|
||||
retval->ref.storeRelaxed(0);
|
||||
retval->m_index = index;
|
||||
retval->m_numberOptions = numberOptions;
|
||||
return retval;
|
||||
}
|
||||
|
||||
static QLocalePrivate *get(QLocale &l) { return l.d; }
|
||||
static const QLocalePrivate *get(const QLocale &l) { return l.d; }
|
||||
constexpr QLocalePrivate(const QLocaleData *data, const uint index,
|
||||
QLocale::NumberOptions numberOptions = QLocale::DefaultNumberOptions,
|
||||
int refs = 0)
|
||||
: m_data(data), ref Q_BASIC_ATOMIC_INITIALIZER(refs),
|
||||
m_index(index), m_numberOptions(numberOptions) {}
|
||||
|
||||
quint16 languageId() const { return m_data->m_language_id; }
|
||||
quint16 countryId() const { return m_data->m_country_id; }
|
||||
@ -419,6 +410,7 @@ public:
|
||||
inline QLatin1String scriptCode() const { return scriptToCode(QLocale::Script(m_data->m_script_id)); }
|
||||
inline QLatin1String countryCode() const { return countryToCode(QLocale::Country(m_data->m_country_id)); }
|
||||
|
||||
static const QLocalePrivate *get(const QLocale &l) { return l.d; }
|
||||
static QLatin1String languageToCode(QLocale::Language language);
|
||||
static QLatin1String scriptToCode(QLocale::Script script);
|
||||
static QLatin1String countryToCode(QLocale::Country country);
|
||||
@ -431,9 +423,9 @@ public:
|
||||
QLocale::MeasurementSystem measurementSystem() const;
|
||||
|
||||
// System locale has an m_data all its own; all others have m_data = locale_data + m_index
|
||||
const QLocaleData *m_data;
|
||||
const QLocaleData *const m_data;
|
||||
QBasicAtomicInt ref;
|
||||
uint m_index;
|
||||
const uint m_index;
|
||||
QLocale::NumberOptions m_numberOptions;
|
||||
};
|
||||
|
||||
@ -446,7 +438,7 @@ inline QLocalePrivate *QSharedDataPointer<QLocalePrivate>::clone()
|
||||
{
|
||||
// cannot use QLocalePrivate's copy constructor
|
||||
// since it is deleted in C++11
|
||||
return QLocalePrivate::create(d->m_data, d->m_index, d->m_numberOptions);
|
||||
return new QLocalePrivate(d->m_data, d->m_index, d->m_numberOptions);
|
||||
}
|
||||
|
||||
inline char QLocaleData::numericToCLocale(QStringView in) const
|
||||
|
Loading…
Reference in New Issue
Block a user