From 79578fd691820aad2c9be3827c376c62c182bb14 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 24 Feb 2023 21:40:46 +0200 Subject: [PATCH] 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 Reviewed-by: Konrad Kujawa Reviewed-by: Edward Welbourne --- src/corelib/kernel/qcore_unix_p.h | 23 +++++++++++------------ src/corelib/kernel/qtimerinfo_unix.cpp | 10 +++------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index c02910b879..ed64a5d86b 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -83,13 +83,13 @@ inline timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept } template -inline Duration timespecToChrono(struct timespec *ts) noexcept +inline Duration timespecToChrono(timespec ts) noexcept { using namespace std::chrono; - return duration_cast(seconds{ts->tv_sec} + nanoseconds{ts->tv_nsec}); + return duration_cast(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(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() diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp index 2c52aaa1ac..390fd96644 100644 --- a/src/corelib/kernel/qtimerinfo_unix.cpp +++ b/src/corelib/kernel/qtimerinfo_unix.cpp @@ -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,13 +396,10 @@ 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)