summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-01-21 10:38:48 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-02-14 08:13:45 +0000
commit4fbd6ee52eee0e5cebe4241c55dfe5c9c4bc15de (patch)
tree8fb41514cec9ac5ba6013665f5c5a4ed1c63530e /src/corelib/tools
parentdb569428c62751aba1aebea658f8cbe3297b16d4 (diff)
QDateTime: use existing functions for short month name parsing
...instead of rolling a new one on each use. Effects on Linux GCC 4.9 stripped release builds: text -156B data +-0B relocs +-0 Change-Id: I49e20ea859928d010990fc7a22545dbc1ef106ec Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qdatetime.cpp56
1 files changed, 21 insertions, 35 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index aa37f8c9da..2b006fe2d5 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -159,7 +159,7 @@ static const char qt_shortMonthNames[][4] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
-int qt_monthNumberFromShortName(const QString &shortName)
+static int qt_monthNumberFromShortName(QStringRef shortName)
{
for (unsigned int i = 0; i < sizeof(qt_shortMonthNames) / sizeof(qt_shortMonthNames[0]); ++i) {
if (shortName == QLatin1String(qt_shortMonthNames[i], 3))
@@ -167,7 +167,23 @@ int qt_monthNumberFromShortName(const QString &shortName)
}
return -1;
}
-#endif
+int qt_monthNumberFromShortName(const QString &shortName)
+{ return qt_monthNumberFromShortName(QStringRef(&shortName)); }
+
+static int fromShortMonthName(const QStringRef &monthName)
+{
+ // Assume that English monthnames are the default
+ int month = qt_monthNumberFromShortName(monthName);
+ if (month != -1)
+ return month;
+ // If English names can't be found, search the localized ones
+ for (int i = 1; i <= 12; ++i) {
+ if (monthName == QDate::shortMonthName(i))
+ return i;
+ }
+ return -1;
+}
+#endif // QT_NO_TEXTDATE
#ifndef QT_NO_DATESTRING
static void rfcDateImpl(const QString &s, QDate *dd = 0, QTime *dt = 0, int *utcOffset = 0)
@@ -1253,25 +1269,10 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
return QDate();
QStringRef monthName = parts.at(1);
- int month = -1;
- // Assume that English monthnames are the default
- for (int i = 0; i < 12; ++i) {
- if (monthName == QLatin1String(qt_shortMonthNames[i])) {
- month = i + 1;
- break;
- }
- }
- // If English names can't be found, search the localized ones
+ const int month = fromShortMonthName(monthName);
if (month == -1) {
- for (int i = 1; i <= 12; ++i) {
- if (monthName == QDate::shortMonthName(i)) {
- month = i;
- break;
- }
- }
- if (month == -1)
- // Month name matches neither English nor other localised name.
- return QDate();
+ // Month name matches neither English nor other localised name.
+ return QDate();
}
bool ok = false;
@@ -4389,21 +4390,6 @@ int QDateTime::utcOffset() const
#ifndef QT_NO_DATESTRING
-static int fromShortMonthName(const QStringRef &monthName)
-{
- // Assume that English monthnames are the default
- for (int i = 0; i < 12; ++i) {
- if (monthName == QLatin1String(qt_shortMonthNames[i]))
- return i + 1;
- }
- // If English names can't be found, search the localized ones
- for (int i = 1; i <= 12; ++i) {
- if (monthName == QDate::shortMonthName(i))
- return i;
- }
- return -1;
-}
-
/*!
\fn QDateTime QDateTime::fromString(const QString &string, Qt::DateFormat format)