[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdecore/date
From: John Layt <john () layt ! net>
Date: 2010-12-15 11:54:03
Message-ID: 20101215115403.C2C7EAC8A8 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1206679 by jlayt:
Fix KDateTimeFormatter to not create an en_US locale unless really needed.
Creating the en_US locale is very inefficent as it triggers an updateCatalogs()
every time, so creating the locale every time a date is parsed is horrifically
inefficient. Delaying the creation until it is actually needed and keeping it
around afterwards is a temporary solution to fix the most common use case, but
is not a long term solution when KDateTime starts using it.
M +33 -16 kdatetimeformatter.cpp
M +7 -0 kdatetimeformatter_p.h
--- trunk/KDE/kdelibs/kdecore/date/kdatetimeformatter.cpp #1206678:1206679
@@ -32,11 +32,15 @@
#include "kdebug.h"
KDateTimeFormatter::KDateTimeFormatter()
+ : m_englishLocale(0),
+ m_englishCalendar(0)
{
}
KDateTimeFormatter::~KDateTimeFormatter()
{
+ delete m_englishCalendar;
+ delete m_englishLocale;
}
QString KDateTimeFormatter::formatDate( const QDate &fromDate,
@@ -128,11 +132,6 @@
int year, month, day;
calendar->getDate( fromDateTime.date(), &year, &month, &day );
- // Set up an English locale and calendar for use with ':' modifier which forces \
English names
- KLocale *englishLocale = new KLocale( *locale );
- englishLocale->setLanguage( QStringList() << QString::fromLatin1("en_US") );
- KCalendarSystem *englishCalendar = KCalendarSystem::create( \
calendar->calendarType(), englishLocale );
-
for ( int formatIndex = 0; formatIndex < toFormat.length(); ++formatIndex ) {
thisChar = toFormat.at( formatIndex );
@@ -312,14 +311,16 @@
if ( locale->dateMonthNamePossessive() ) {
if ( modifierChar == QLatin1Char(':') ) {
invalidModifier = false;
- componentString = englishCalendar->monthName( month, \
year, KCalendarSystem::LongNamePossessive ); + \
initEnglish( calendar, locale ); + componentString = \
m_englishCalendar->monthName( month, year, KCalendarSystem::LongNamePossessive ); } \
else {
componentString = calendar->monthName( month, year, \
KCalendarSystem::LongNamePossessive ); }
} else {
if ( modifierChar == QLatin1Char(':') ) {
invalidModifier = false;
- componentString = englishCalendar->monthName( month, \
year, KCalendarSystem::LongName ); + initEnglish( \
calendar, locale ); + componentString = \
m_englishCalendar->monthName( month, year, KCalendarSystem::LongName ); } else {
componentString = calendar->monthName( month, year, \
KCalendarSystem::LongName ); }
@@ -333,14 +334,16 @@
if ( locale->dateMonthNamePossessive() ) {
if ( modifierChar == QLatin1Char(':') ) {
invalidModifier = false;
- componentString = englishCalendar->monthName( month, \
year, KCalendarSystem::ShortNamePossessive ); + \
initEnglish( calendar, locale ); + componentString = \
m_englishCalendar->monthName( month, year, KCalendarSystem::ShortNamePossessive ); } \
else {
componentString = calendar->monthName( month, year, \
KCalendarSystem::ShortNamePossessive ); }
} else {
if ( modifierChar == QLatin1Char(':') ) {
invalidModifier = false;
- componentString = englishCalendar->monthName( month, \
year, KCalendarSystem::ShortName ); + initEnglish( \
calendar, locale ); + componentString = \
m_englishCalendar->monthName( month, year, KCalendarSystem::ShortName ); } else {
componentString = calendar->monthName( month, year, \
KCalendarSystem::ShortName ); }
@@ -352,7 +355,8 @@
case 'A': //Long weekday name, default space pad to 0 places no \
sign if ( modifierChar == QLatin1Char(':') ) {
invalidModifier = false;
- componentString = englishCalendar->weekDayName( \
fromDateTime.date(), KCalendarSystem::LongDayName ); + \
initEnglish( calendar, locale ); + componentString = \
m_englishCalendar->weekDayName( fromDateTime.date(), KCalendarSystem::LongDayName ); \
} else {
componentString = calendar->weekDayName( \
fromDateTime.date(), KCalendarSystem::LongDayName ); }
@@ -363,7 +367,8 @@
case 'a': //Short weekday name, default space pad to 0 places no \
sign if ( modifierChar == QLatin1Char(':') ) {
invalidModifier = false;
- componentString = englishCalendar->weekDayName( \
fromDateTime.date(), KCalendarSystem::ShortDayName ); + \
initEnglish( calendar, locale ); + componentString = \
m_englishCalendar->weekDayName( fromDateTime.date(), KCalendarSystem::ShortDayName ); \
} else {
componentString = calendar->weekDayName( \
fromDateTime.date(), KCalendarSystem::ShortDayName ); }
@@ -486,7 +491,7 @@
case 'S': // Long seconds
invalidModifier = false;
if ( (timeOptions & KLocale::TimeWithoutSeconds) == \
KLocale::TimeWithoutSeconds ) {
- //do strip the preceeding/following punctuation
+ //TODO strip the preceeding/following punctuation
} else {
componentInteger = fromDateTime.time().second();
if ( modifierChar == QLatin1Char(':') ) { // Only if not 00 \
seconds @@ -513,11 +518,12 @@
case 'p': // AM/PM symbol
case 'P': // AM/PM symbol in lowercase
if ( (timeOptions & KLocale::TimeWithoutAmPm) == \
KLocale::TimeWithoutAmPm ) {
- //do strip the preceeding/following punctuation
+ //TODO strip the preceeding/following punctuation
} else {
if ( modifierChar == QLatin1Char(':') ) {
invalidModifier = false;
- componentString = englishLocale->dayPeriodForTime( \
fromDateTime.time() ).periodName( KLocale::ShortName ); + \
initEnglish( calendar, locale ); + componentString = \
m_englishLocale->dayPeriodForTime( fromDateTime.time() ).periodName( \
KLocale::ShortName ); } else {
componentString = locale->dayPeriodForTime( \
fromDateTime.time() ).periodName( KLocale::ShortName ); }
@@ -613,11 +619,22 @@
}
//kDebug() << " return = " << result;
//kDebug() << "";
- delete englishCalendar;
- delete englishLocale;
return result;
}
+void KDateTimeFormatter::initEnglish( const KCalendarSystem *calendar, const KLocale \
*locale ) const +{
+ if ( !m_englishCalendar || m_englishCalendar->calendarType() != \
calendar->calendarType() ) { + // Set up an English locale and calendar \
for use with ':' modifier which forces English names + if ( \
!m_englishLocale ) { + m_englishLocale = new KLocale( *locale );
+ m_englishLocale->setLanguage( QStringList() << \
QString::fromLatin1("en_US") ); + }
+ delete m_englishCalendar;
+ m_englishCalendar = KCalendarSystem::create( calendar->calendarType(), \
m_englishLocale ); + }
+}
+
// Reimplement if special string handling required
// Format an input date to match a UNICODE date format string
// Original QDate::fmtDateTime() code taken from Qt 4.7 under LGPL, now heavily \
modifed
--- trunk/KDE/kdelibs/kdecore/date/kdatetimeformatter_p.h #1206678:1206679
@@ -70,6 +70,8 @@
KLocale::DigitSet digitSet,
KLocale::DateTimeFormatStandard standard ) \
const;
+ virtual void initEnglish( const KCalendarSystem *calendar, const KLocale *locale \
) const; +
virtual QString formatDateTimeUnicode( const KDateTime &fromDateTime,
const QString &toFormat,
KLocale::TimeFormatOptions timeOptions,
@@ -86,6 +88,11 @@
virtual QString stringFromInteger( int number, int padWidth, QChar padChar, \
QChar signChar,
KLocale::DigitSet digitSet, const KLocale \
*locale ) const; +
+ // Is private class, but if ever made public need to move these into a d->
+ // Some format modifiers force English names to be returned
+ mutable KLocale *m_englishLocale;
+ mutable KCalendarSystem *m_englishCalendar;
};
#endif // KDATETIMEFORMATTER_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic