Commit 74a286a6 authored by Robert Krawitz's avatar Robert Krawitz

Un-inline all of the constructors except the copy constructor (that

needs to be as written for performance).

Remove no longer needed setTimeSpec in DateBarWidget, as the rationale
for that has gone away.
parent f0af73d2
......@@ -595,11 +595,7 @@ DB::ImageDate DateBar::DateBarWidget::rangeAt(const QPoint &p)
DB::ImageDate DateBar::DateBarWidget::rangeForUnit(int unit)
{
// Note on the use of setTimeSpec.
// It came to my attention that addSec would create a Utilities::FastDateTime with internal type LocalStandard, while all the others would have type LocalUnknown,
// this resulted in that Utilities::FastDateTime::operator<() would call getUTC(), which took 90% of the time for populating the datebar.
Utilities::FastDateTime toUnit = dateForUnit(unit + 1).addSecs(-1);
toUnit.setTimeSpec(Qt::LocalTime);
return DB::ImageDate(dateForUnit(unit), toUnit);
}
......
......@@ -19,16 +19,36 @@
#include "FastDateTime.h"
namespace {
qint64 toValidatedMSecs(const QDateTime& dateTime) {
static inline qint64 toValidatedMSecs(const QDateTime& dateTime) {
return dateTime.isValid() ? dateTime.toMSecsSinceEpoch() : INT64_MIN;
}
}
Utilities::FastDateTime::FastDateTime()
: m_dateTime(),
m_msecsSinceEpoch(toValidatedMSecs(m_dateTime))
{
}
Utilities::FastDateTime::FastDateTime(const QDate &d, const QTime &t,
Qt::TimeSpec spec)
: m_dateTime(d, t, spec),
m_msecsSinceEpoch(toValidatedMSecs(m_dateTime))
{
}
Utilities::FastDateTime::FastDateTime(const QDateTime &other)
: m_dateTime(other),
m_msecsSinceEpoch(toValidatedMSecs(m_dateTime))
{
}
Utilities::FastDateTime
Utilities::FastDateTime::addDays(qint64 days) const
{
FastDateTime answer(*this);
answer.m_dateTime = answer.m_dateTime.addDays(days);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer.m_dateTime);
return answer;
}
......@@ -37,7 +57,7 @@ Utilities::FastDateTime::addMonths(qint64 months) const
{
FastDateTime answer(*this);
answer.m_dateTime = answer.m_dateTime.addMonths(months);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer.m_dateTime);
return answer;
}
......@@ -46,7 +66,7 @@ Utilities::FastDateTime::addYears(qint64 years) const
{
FastDateTime answer(*this);
answer.m_dateTime = answer.m_dateTime.addYears(years);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer.m_dateTime);
return answer;
}
......@@ -55,7 +75,7 @@ Utilities::FastDateTime::addSecs(qint64 secs) const
{
FastDateTime answer(*this);
answer.m_dateTime = answer.m_dateTime.addSecs(secs);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer);
answer.m_msecsSinceEpoch = toValidatedMSecs(answer.m_dateTime);
return answer;
}
......
......@@ -41,11 +41,11 @@ namespace Utilities
class FastDateTime
{
public:
FastDateTime() : m_dateTime(), m_msecsSinceEpoch(m_dateTime.isValid() ? m_dateTime.toMSecsSinceEpoch() : INT64_MIN) {}
FastDateTime(const QDate &d, const QTime &t, Qt::TimeSpec spec = Qt::LocalTime) : m_dateTime(d, t, spec), m_msecsSinceEpoch(m_dateTime.isValid() ? m_dateTime.toMSecsSinceEpoch() : INT64_MIN) {}
FastDateTime();
FastDateTime(const QDate &d, const QTime &t, Qt::TimeSpec spec = Qt::LocalTime);
FastDateTime(const FastDateTime &other) : m_dateTime(other.m_dateTime), m_msecsSinceEpoch(other.m_msecsSinceEpoch) {}
// Needed for QDate(Y, M, D).startOfDay()
FastDateTime(const QDateTime &other) : m_dateTime(other), m_msecsSinceEpoch(m_dateTime.isValid() ? m_dateTime.toMSecsSinceEpoch() : INT64_MIN) {}
FastDateTime(const QDateTime &other);
~FastDateTime() {};
Q_DECL_CONSTEXPR bool operator==(const FastDateTime &other) const { if (isOK() && other.isOK()) return m_msecsSinceEpoch == other.m_msecsSinceEpoch; else return m_dateTime == other.m_dateTime; }
......@@ -64,7 +64,6 @@ public:
qint64 toSecsSinceEpoch() const { if (isOK()) return m_msecsSinceEpoch / 1000; else return m_dateTime.toSecsSinceEpoch(); }
FastDateTime& operator=(const Utilities::FastDateTime &other) noexcept { if (&other != this) { m_dateTime = other.m_dateTime; m_msecsSinceEpoch = other.m_msecsSinceEpoch; } return *this; }
void setTimeSpec(Qt::TimeSpec spec) { m_dateTime.setTimeSpec(spec); m_msecsSinceEpoch = m_dateTime.isValid() ? m_dateTime.toMSecsSinceEpoch() : INT64_MIN; }
Q_REQUIRED_RESULT FastDateTime addDays(qint64 days) const;
Q_REQUIRED_RESULT FastDateTime addMonths(qint64 months) const;
Q_REQUIRED_RESULT FastDateTime addYears(qint64 years) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment