summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@theqtcompany.com>2016-04-04 10:58:06 +0200
committerEdward Welbourne <edward.welbourne@theqtcompany.com>2016-04-05 11:43:30 +0000
commitbebf89e1379d6948728a4ebd669de6b63dc3f426 (patch)
tree168e93bb1c2822341f3c1dfa570fff770b6af4e6 /src/corelib
parent17d17a5d72d4f98b692c8ab8a7037aa29b503dae (diff)
QDateTimeParser: Avoid repetition in sectionMaxSize
The format to use was computed, every time round a loop, in both branches of a ?: choice, duplicating code and potentially computation. Pull it out into a const computed once before the loop. A conditional return 2 is pointless for the #if-branch which returns 2 unconditionally, so move it into the #else. Change-Id: Ia583e958e24f9f37b92cb3f2a173bc07e88bcd06 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qdatetimeparser.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp
index d4004098c5..8e3eaf7074 100644
--- a/src/corelib/tools/qdatetimeparser.cpp
+++ b/src/corelib/tools/qdatetimeparser.cpp
@@ -598,19 +598,20 @@ int QDateTimeParser::sectionMaxSize(Section s, int count) const
// fall through
#endif
case MonthSection:
- if (count <= 2)
- return 2;
-
#ifdef QT_NO_TEXTDATE
return 2;
#else
+ if (count <= 2)
+ return 2;
+
{
int ret = 0;
const QLocale l = locale();
+ const QLocale::FormatType format = count == 4 ? QLocale::LongFormat : QLocale::ShortFormat;
for (int i=1; i<=mcount; ++i) {
const QString str = (s == MonthSection
- ? l.monthName(i, count == 4 ? QLocale::LongFormat : QLocale::ShortFormat)
- : l.dayName(i, count == 4 ? QLocale::LongFormat : QLocale::ShortFormat));
+ ? l.monthName(i, format)
+ : l.dayName(i, format));
ret = qMax(str.size(), ret);
}
return ret;