From bebf89e1379d6948728a4ebd669de6b63dc3f426 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 4 Apr 2016 10:58:06 +0200 Subject: [PATCH] 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 --- src/corelib/tools/qdatetimeparser.cpp | 11 ++++++----- 1 file 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;