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>
bb10
Edward Welbourne 2016-04-04 10:58:06 +02:00
parent 17d17a5d72
commit bebf89e137
1 changed files with 6 additions and 5 deletions

View File

@ -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;