Tidy up QTimeZone method bodies

Use ternary operator form, or boolean algebra, for the short returns.
Handling invalid differently from valid isn't symmetric, they're
qualitatively different branches.
Skip a fatuous default-initialization.

Change-Id: I01a8a06055c315ecf08fc87d208808c0fe71eb31
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Edward Welbourne 2020-08-28 15:42:41 +02:00
parent 2f6964ea00
commit 150828254a
1 changed files with 27 additions and 55 deletions

View File

@ -386,7 +386,6 @@ QTimeZone::QTimeZone(int offsetSeconds)
QTimeZone::QTimeZone(const QByteArray &ianaId, int offsetSeconds, const QString &name,
const QString &abbreviation, QLocale::Country country, const QString &comment)
: d()
{
if (!isTimeZoneIdAvailable(ianaId))
d = new QUtcTimeZonePrivate(ianaId, offsetSeconds, name, abbreviation, country, comment);
@ -457,10 +456,7 @@ QTimeZone &QTimeZone::operator=(const QTimeZone &other)
bool QTimeZone::operator==(const QTimeZone &other) const
{
if (d && other.d)
return (*d == *other.d);
else
return (d == other.d);
return d == other.d || (d && other.d && *d == *other.d);
}
/*!
@ -469,10 +465,7 @@ bool QTimeZone::operator==(const QTimeZone &other) const
bool QTimeZone::operator!=(const QTimeZone &other) const
{
if (d && other.d)
return (*d != *other.d);
else
return (d != other.d);
return d != other.d && (!d || !other.d || *d != *other.d);
}
/*!
@ -481,10 +474,7 @@ bool QTimeZone::operator!=(const QTimeZone &other) const
bool QTimeZone::isValid() const
{
if (d)
return d->isValid();
else
return false;
return d && d->isValid();
}
/*!
@ -496,10 +486,7 @@ bool QTimeZone::isValid() const
QByteArray QTimeZone::id() const
{
if (d)
return d->id();
else
return QByteArray();
return d ? d->id() : QByteArray();
}
/*!
@ -508,10 +495,7 @@ QByteArray QTimeZone::id() const
QLocale::Country QTimeZone::country() const
{
if (isValid())
return d->country();
else
return QLocale::AnyCountry;
return isValid() ? d->country() : QLocale::AnyCountry;
}
/*!
@ -524,10 +508,7 @@ QLocale::Country QTimeZone::country() const
QString QTimeZone::comment() const
{
if (isValid())
return d->comment();
else
return QString();
return isValid() ? d->comment() : QString();
}
/*!
@ -549,8 +530,8 @@ QString QTimeZone::displayName(const QDateTime &atDateTime, NameType nameType,
{
if (isValid())
return d->displayName(atDateTime.toMSecsSinceEpoch(), nameType, locale);
else
return QString();
return QString();
}
/*!
@ -573,8 +554,8 @@ QString QTimeZone::displayName(TimeType timeType, NameType nameType,
{
if (isValid())
return d->displayName(timeType, nameType, locale);
else
return QString();
return QString();
}
/*!
@ -591,8 +572,8 @@ QString QTimeZone::abbreviation(const QDateTime &atDateTime) const
{
if (isValid())
return d->abbreviation(atDateTime.toMSecsSinceEpoch());
else
return QString();
return QString();
}
/*!
@ -613,8 +594,8 @@ int QTimeZone::offsetFromUtc(const QDateTime &atDateTime) const
{
if (isValid())
return d->offsetFromUtc(atDateTime.toMSecsSinceEpoch());
else
return 0;
return 0;
}
/*!
@ -633,8 +614,8 @@ int QTimeZone::standardTimeOffset(const QDateTime &atDateTime) const
{
if (isValid())
return d->standardTimeOffset(atDateTime.toMSecsSinceEpoch());
else
return 0;
return 0;
}
/*!
@ -653,8 +634,8 @@ int QTimeZone::daylightTimeOffset(const QDateTime &atDateTime) const
{
if (hasDaylightTime())
return d->daylightTimeOffset(atDateTime.toMSecsSinceEpoch());
else
return 0;
return 0;
}
/*!
@ -665,10 +646,7 @@ int QTimeZone::daylightTimeOffset(const QDateTime &atDateTime) const
bool QTimeZone::hasDaylightTime() const
{
if (isValid())
return d->hasDaylightTime();
else
return false;
return isValid() && d->hasDaylightTime();
}
/*!
@ -679,10 +657,7 @@ bool QTimeZone::hasDaylightTime() const
bool QTimeZone::isDaylightTime(const QDateTime &atDateTime) const
{
if (hasDaylightTime())
return d->isDaylightTime(atDateTime.toMSecsSinceEpoch());
else
return false;
return hasDaylightTime() && d->isDaylightTime(atDateTime.toMSecsSinceEpoch());
}
/*!
@ -697,8 +672,8 @@ QTimeZone::OffsetData QTimeZone::offsetData(const QDateTime &forDateTime) const
{
if (hasTransitions())
return QTimeZonePrivate::toOffsetData(d->data(forDateTime.toMSecsSinceEpoch()));
else
return QTimeZonePrivate::invalidOffsetData();
return QTimeZonePrivate::invalidOffsetData();
}
/*!
@ -712,10 +687,7 @@ QTimeZone::OffsetData QTimeZone::offsetData(const QDateTime &forDateTime) const
bool QTimeZone::hasTransitions() const
{
if (isValid())
return d->hasTransitions();
else
return false;
return isValid() && d->hasTransitions();
}
/*!
@ -735,8 +707,8 @@ QTimeZone::OffsetData QTimeZone::nextTransition(const QDateTime &afterDateTime)
{
if (hasTransitions())
return QTimeZonePrivate::toOffsetData(d->nextTransition(afterDateTime.toMSecsSinceEpoch()));
else
return QTimeZonePrivate::invalidOffsetData();
return QTimeZonePrivate::invalidOffsetData();
}
/*!
@ -756,8 +728,8 @@ QTimeZone::OffsetData QTimeZone::previousTransition(const QDateTime &beforeDateT
{
if (hasTransitions())
return QTimeZonePrivate::toOffsetData(d->previousTransition(beforeDateTime.toMSecsSinceEpoch()));
else
return QTimeZonePrivate::invalidOffsetData();
return QTimeZonePrivate::invalidOffsetData();
}
/*!