q_core_unix: take timespec args by value

From the review, timespecS are trivial and small, so they get passed in
registers anyway.

Change-Id: Iedf1f17af1fd58643a0c103230b1fea3c2fe1e49
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Ahmad Samir 2023-02-24 21:40:46 +02:00
parent 0f447e875d
commit 79578fd691
2 changed files with 14 additions and 19 deletions

View File

@ -83,13 +83,13 @@ inline timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept
}
template <typename Duration>
inline Duration timespecToChrono(struct timespec *ts) noexcept
inline Duration timespecToChrono(timespec ts) noexcept
{
using namespace std::chrono;
return duration_cast<Duration>(seconds{ts->tv_sec} + nanoseconds{ts->tv_nsec});
return duration_cast<Duration>(seconds{ts.tv_sec} + nanoseconds{ts.tv_nsec});
}
inline std::chrono::milliseconds timespecToChronoMs(struct timespec *ts) noexcept
inline std::chrono::milliseconds timespecToChronoMs(timespec ts) noexcept
{
return timespecToChrono<std::chrono::milliseconds>(ts);
}
@ -140,7 +140,7 @@ constexpr inline timespec operator*(const timespec &t1, int mul)
tmp.tv_nsec = t1.tv_nsec * mul;
return normalizedTimespec(tmp);
}
inline timeval timespecToTimeval(const timespec &ts)
inline timeval timespecToTimeval(timespec ts)
{
timeval tv;
tv.tv_sec = ts.tv_sec;
@ -172,17 +172,16 @@ inline timespec operator+(const timespec &t1, int ms)
return t1 + std::chrono::milliseconds{ms};
}
inline timespec qAbsTimespec(const timespec &t)
inline timespec qAbsTimespec(timespec ts)
{
timespec tmp = t;
if (tmp.tv_sec < 0) {
tmp.tv_sec = -tmp.tv_sec - 1;
tmp.tv_nsec -= OneSecAsNsecs;
if (ts.tv_sec < 0) {
ts.tv_sec = -ts.tv_sec - 1;
ts.tv_nsec -= OneSecAsNsecs;
}
if (tmp.tv_sec == 0 && tmp.tv_nsec < 0) {
tmp.tv_nsec = -tmp.tv_nsec;
if (ts.tv_sec == 0 && ts.tv_nsec < 0) {
ts.tv_nsec = -ts.tv_nsec;
}
return normalizedTimespec(tmp);
return normalizedTimespec(ts);
}
inline void qt_ignore_sigpipe()

View File

@ -386,7 +386,6 @@ milliseconds QTimerInfoList::remainingDuration(int timerId)
{
timespec now = updateCurrentTime();
repairTimersIfNeeded();
timespec tm = {0, 0};
auto it = findTimerById(timerId);
if (it == cend()) {
@ -397,14 +396,11 @@ milliseconds QTimerInfoList::remainingDuration(int timerId)
}
const QTimerInfo *t = *it;
if (now < t->timeout) {
// time to wait
tm = roundToMillisecond(t->timeout - now);
return timespecToChronoMs(&tm);
} else {
if (now < t->timeout) // time to wait
return timespecToChronoMs(roundToMillisecond(t->timeout - now));
else
return milliseconds{0};
}
}
void QTimerInfoList::registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object)
{