aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike FABIAN <mike.fabian@basyskom.de>2010-12-10 16:45:24 +0100
committerMike FABIAN <mike.fabian@basyskom.de>2010-12-10 17:02:37 +0100
commit76dd34e5a1c3780b0351412a87b0b437455e6f1d (patch)
tree20206ec52680a27d90d3686a7b760ba92f91a5a2
parent519a3896dbfb1d8f14be12690a8d8375fc99b11c (diff)
Fixes: NB#210881, calendar app crashing on trying to add new event
RevBy: Holger Schröder Details: Fix it by using mutable QCache<QString, icu::DateFormat> _dateFormatCache; instead of a pointer as the member variable in MLocalePrivate. Adding a _dateFormatCache = 0; after the delete _dateFormatCache; in the operator= and adding a “delete _dateFormatCache;” in the destructor would have fixed the problem as well of course, but not using a pointer also fixes the problem. My idea of using the pointer was to avoid calling the constructor of QCache unless really needed to make construction of MLocale objects cheaper. Maybe a MLocale object doesn’t need date and time formatting at all, then it also doesn’t need that cache. But Holger convinced me that creating a QCache is very cheap.
-rw-r--r--src/corelib/i18n/mlocale.cpp11
-rw-r--r--src/corelib/i18n/mlocale_p.h2
2 files changed, 4 insertions, 9 deletions
diff --git a/src/corelib/i18n/mlocale.cpp b/src/corelib/i18n/mlocale.cpp
index b024b759..5b245795 100644
--- a/src/corelib/i18n/mlocale.cpp
+++ b/src/corelib/i18n/mlocale.cpp
@@ -505,8 +505,8 @@ icu::DateFormat *MLocalePrivate::createDateFormat(MLocale::DateType dateType,
.arg(calendarType)
.arg(timeFormat24h)
.arg(categoryName(MLocale::MLcTime));
- if (_dateFormatCache && _dateFormatCache->contains(key))
- return _dateFormatCache->object(key);
+ if (_dateFormatCache.contains(key))
+ return _dateFormatCache.object(key);
// Create calLocale which has the time pattern we want to use
icu::Locale calLocale = MIcuConversions::createLocale(
categoryName(MLocale::MLcTime),
@@ -542,9 +542,7 @@ icu::DateFormat *MLocalePrivate::createDateFormat(MLocale::DateType dateType,
break;
}
}
- if (!_dateFormatCache)
- _dateFormatCache = new QCache<QString, icu::DateFormat>;
- _dateFormatCache->insert(key, df);
+ _dateFormatCache.insert(key, df);
return df;
}
#endif
@@ -560,7 +558,6 @@ MLocalePrivate::MLocalePrivate()
#ifdef HAVE_ICU
_numberFormat(0),
_numberFormatLcTime(0),
- _dateFormatCache(0),
#endif
#ifdef HAVE_GCONF
currentLanguageItem(SettingsLanguage),
@@ -598,7 +595,6 @@ MLocalePrivate::MLocalePrivate(const MLocalePrivate &other)
#ifdef HAVE_ICU
_numberFormat(0),
_numberFormatLcTime(0),
- _dateFormatCache(0),
#endif
_messageTranslations(other._messageTranslations),
_timeTranslations(other._timeTranslations),
@@ -669,7 +665,6 @@ MLocalePrivate &MLocalePrivate::operator=(const MLocalePrivate &other)
} else {
_numberFormatLcTime = 0;
}
- delete _dateFormatCache;
#endif
return *this;
diff --git a/src/corelib/i18n/mlocale_p.h b/src/corelib/i18n/mlocale_p.h
index 269d9554..e459ed17 100644
--- a/src/corelib/i18n/mlocale_p.h
+++ b/src/corelib/i18n/mlocale_p.h
@@ -183,7 +183,7 @@ public:
// number format caching for better performance.
icu::NumberFormat *_numberFormat;
icu::NumberFormat *_numberFormatLcTime;
- mutable QCache<QString, icu::DateFormat> *_dateFormatCache;
+ mutable QCache<QString, icu::DateFormat> _dateFormatCache;
#endif
// translations for two supported translation categories