From df252fc2051a6d2939c77244e74aca4a115d7cce Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 15 Dec 2016 10:55:36 +0100 Subject: Tidy up QDateTimeParser in assorted petty ways A bit-field was necessarily equal to either zero or its (single-bit) mask; so comparing to the mask was superfluous. A local value set and then conditionally over-ridden could easily be made const by using the condition in a ?: assignment. A use of qMin() lent itself to turning into a simple conditional assignment. Change-Id: I541d98044b23b8c51e6169f617a5841ba8fffc55 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetimeparser.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/corelib/tools/qdatetimeparser.cpp') diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index d49bec5f763..632ff4c8e71 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -705,7 +705,7 @@ int QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionInde state = Invalid; int num = 0; const SectionNode &sn = sectionNode(sectionIndex); - if ((sn.type & Internal) == Internal) { + if (sn.type & Internal) { qWarning("QDateTimeParser::parseSection Internal error (%s %d)", qPrintable(sn.name()), sectionIndex); return -1; @@ -756,11 +756,9 @@ int QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionInde if (sn.count >= 3) { QString sectiontext = sectionTextRef.toString(); if (sn.type == MonthSection) { - int min = 1; const QDate minDate = getMinimum().date(); - if (currentValue.date().year() == minDate.year()) { - min = minDate.month(); - } + const int min = (currentValue.date().year() == minDate.year()) + ? minDate.month() : 1; num = findMonth(sectiontext.toLower(), min, sectionIndex, §iontext, &used); } else { num = findDay(sectiontext.toLower(), 1, sectionIndex, §iontext, &used); @@ -1065,8 +1063,8 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos input.replace(sectionPos(sn), sectionSize(i), dayName); } } - } else { - state = qMin(Intermediate, state); + } else if (state > Intermediate) { + state = Intermediate; } } } -- cgit v1.2.3