summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-04-28 22:32:40 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-30 17:21:21 +0200
commit08ac38a6e368b56d4dfdd872b62eafe13cd93157 (patch)
tree43291d71532920260cf425f28d077ddba5244e28 /src/corelib
parent50ab31a5dfe491510e194e58075b648fd0b47e6a (diff)
Make QLocalePrivate POD
QSharedDataPointer does not actually need a class derived from QSharedData. All it needs is a member called "ref". Change-Id: I2f7fe4cc143478ef7ef64681eada16e2d4c2e63a Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qlocale.cpp10
-rw-r--r--src/corelib/tools/qlocale_p.h23
2 files changed, 21 insertions, 12 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index a8b2b9fedb..915a83e156 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -702,12 +702,12 @@ const QLocaleData *QLocalePrivate::dataPointerForIndex(quint16 index)
static QLocalePrivate *localePrivateByName(const QString &name)
{
- return new QLocalePrivate(findLocaleData(name));
+ return QLocalePrivate::create(findLocaleData(name));
}
static QLocalePrivate *defaultLocalePrivate()
{
- return new QLocalePrivate(defaultData(), default_number_options);
+ return QLocalePrivate::create(defaultData(), default_number_options);
}
static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script,
@@ -722,7 +722,7 @@ static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Sc
numberOptions = default_number_options;
data = defaultData();
}
- return new QLocalePrivate(data, numberOptions);
+ return QLocalePrivate::create(data, numberOptions);
}
@@ -2108,7 +2108,7 @@ QString QLocale::toString(double i, char f, int prec) const
QLocale QLocale::system()
{
- return QLocale(*new QLocalePrivate(systemData()));
+ return QLocale(*QLocalePrivate::create(systemData()));
}
@@ -2143,7 +2143,7 @@ QList<QLocale> QLocale::matchingLocales(QLocale::Language language,
&& (language == QLocale::AnyLanguage || data->m_language_id == uint(language))) {
if ((script == QLocale::AnyScript || data->m_script_id == uint(script))
&& (country == QLocale::AnyCountry || data->m_country_id == uint(country))) {
- QLocale locale(*new QLocalePrivate(data));
+ QLocale locale(*QLocalePrivate::create(data));
result.append(locale);
}
++data;
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index 9ed1b6bf76..a6136ea774 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -205,16 +205,16 @@ public:
quint16 m_weekend_end : 3;
};
-class Q_CORE_EXPORT QLocalePrivate : public QSharedData
+class Q_CORE_EXPORT QLocalePrivate
{
public:
- explicit QLocalePrivate(const QLocaleData *data, int numberOptions = 0)
- : m_data(data), m_numberOptions(numberOptions)
- {
- }
-
- ~QLocalePrivate()
+ static QLocalePrivate *create(const QLocaleData *data, int numberOptions = 0)
{
+ QLocalePrivate *retval = new QLocalePrivate;
+ retval->m_data = data;
+ retval->ref.store(1);
+ retval->m_numberOptions = numberOptions;
+ return retval;
}
QChar decimal() const { return QChar(m_data->m_decimal); }
@@ -332,9 +332,18 @@ public:
const QLocale *q) const;
const QLocaleData *m_data;
+ QBasicAtomicInt ref;
quint16 m_numberOptions;
};
+template <>
+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_numberOptions);
+}
+
inline char QLocalePrivate::digitToCLocale(QChar in) const
{
const QChar _zero = zero();