QSingleShotTimer: de-inline [3/4]: move fromMSecs to qtimer.cpp

Move the implementation of fromSecs() from the header to the
qtimer.cpp file and make it file-static. There are no callers of the
function outside qtimer.cpp.

Amends e0573e73645c0f57e46332a94160e28eb6c8ebac.

As a drive-by, rename the function to snake_case to indicate that it's
a file-static.

Change-Id: Ifa32df8a28816cd9cae44cdb9d481df94d33d741
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit ba80845ed16b784ac00dcc9e7715e4605e3344ff)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-06-28 10:18:20 +02:00 committed by Qt Cherry-pick Bot
parent 4e209c2188
commit 431ca49614
2 changed files with 19 additions and 20 deletions

View File

@ -19,9 +19,6 @@
#include "qabstracteventdispatcher.h" #include "qabstracteventdispatcher.h"
#include "qcoreapplication.h" #include "qcoreapplication.h"
#include "qmetaobject_p.h" #include "qmetaobject_p.h"
#include "private/qnumeric_p.h"
#include <chrono>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -43,21 +40,6 @@ public:
void startTimerForReceiver(Duration interval, Qt::TimerType timerType, void startTimerForReceiver(Duration interval, Qt::TimerType timerType,
const QObject *receiver); const QObject *receiver);
static Duration fromMsecs(std::chrono::milliseconds ms)
{
using namespace std::chrono;
using ratio = std::ratio_divide<std::milli, Duration::period>;
static_assert(ratio::den == 1);
Duration::rep r;
if (qMulOverflow<ratio::num>(ms.count(), &r)) {
qWarning("QTimer::singleShot(std::chrono::milliseconds, ...): "
"interval argument overflowed when converted to nanoseconds.");
return Duration::max();
}
return Duration{r};
}
Q_SIGNALS: Q_SIGNALS:
void timeout(); void timeout();

View File

@ -288,6 +288,23 @@ void QTimer::timerEvent(QTimerEvent *e)
} }
} }
static QAbstractEventDispatcher::Duration from_msecs(std::chrono::milliseconds ms)
{
using Duration = QAbstractEventDispatcher::Duration;
using namespace std::chrono;
using ratio = std::ratio_divide<std::milli, Duration::period>;
static_assert(ratio::den == 1);
Duration::rep r;
if (qMulOverflow<ratio::num>(ms.count(), &r)) {
qWarning("QTimer::singleShot(std::chrono::milliseconds, ...): "
"interval argument overflowed when converted to nanoseconds.");
return Duration::max();
}
return Duration{r};
}
/*! /*!
\internal \internal
@ -332,7 +349,7 @@ void QTimer::singleShotImpl(std::chrono::milliseconds msec, Qt::TimerType timerT
return; return;
} }
new QSingleShotTimer(QSingleShotTimer::fromMsecs(msec), timerType, receiver, slotObj); new QSingleShotTimer(from_msecs(msec), timerType, receiver, slotObj);
} }
/*! /*!
@ -396,7 +413,7 @@ void QTimer::singleShot(std::chrono::milliseconds msec, Qt::TimerType timerType,
Qt::QueuedConnection); Qt::QueuedConnection);
return; return;
} }
(void) new QSingleShotTimer(QSingleShotTimer::fromMsecs(msec), timerType, receiver, member); (void) new QSingleShotTimer(from_msecs(msec), timerType, receiver, member);
} }
} }