From 903157444098035ba8372f0951543b7756a2ec0f Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 11 Jan 2023 20:28:27 +0100 Subject: [PATCH] Make QDateTime::Data::CanBeSmall a static constexpr bool Using enum for named constants is old-fashioned. Also test it using if constexpr, since we can. Change-Id: I1fc4ed975e12403bc724b39f9335f3797acfafb8 Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetime.cpp | 4 ++-- src/corelib/time/qdatetime.h | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index e6eb2a0a701..f6e7c511cb2 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -2782,7 +2782,7 @@ static inline bool specCanBeSmall(Qt::TimeSpec spec) static inline bool msecsCanBeSmall(qint64 msecs) { - if (!QDateTimeData::CanBeSmall) + if constexpr (!QDateTimeData::CanBeSmall) return false; ShortData sd; @@ -3161,7 +3161,7 @@ inline bool QDateTime::Data::isShort() const // even if CanBeSmall = false, we have short data for a default-constructed // QDateTime object. But it's unlikely. - if (CanBeSmall) + if constexpr (CanBeSmall) return Q_LIKELY(b); return Q_UNLIKELY(b); } diff --git a/src/corelib/time/qdatetime.h b/src/corelib/time/qdatetime.h index 240fcc06328..04da60469ec 100644 --- a/src/corelib/time/qdatetime.h +++ b/src/corelib/time/qdatetime.h @@ -281,12 +281,10 @@ class Q_CORE_EXPORT QDateTime }; union Data { - enum { - // To be of any use, we need at least 60 years around 1970, which - // is 1,893,456,000,000 ms. That requires 41 bits to store, plus - // the sign bit. With the status byte, the minimum size is 50 bits. - CanBeSmall = sizeof(ShortData) * 8 > 50 - }; + // To be of any use, we need at least 60 years around 1970, which + // is 1,893,456,000,000 ms. That requires 41 bits to store, plus + // the sign bit. With the status byte, the minimum size is 50 bits. + static constexpr bool CanBeSmall = sizeof(ShortData) * 8 > 50; Data() noexcept; Data(const QTimeZone &);