perf: avoid extra time() call (#4577)

This commit is contained in:
Dmitry Antipov 2023-01-11 18:26:58 +03:00 committed by GitHub
parent 0af121004c
commit a5c7b65869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -609,13 +609,13 @@ tr_session* tr_sessionInit(char const* config_dir, bool message_queueing_enabled
void tr_session::onNowTimer()
{
TR_ASSERT(now_timer_);
auto const now = std::chrono::system_clock::now();
// tr_session upkeep tasks to perform once per second
tr_timeUpdate(time(nullptr));
tr_timeUpdate(std::chrono::system_clock::to_time_t(now));
alt_speeds_.checkScheduler();
// set the timer to kick again right after (10ms after) the next second
auto const now = std::chrono::system_clock::now();
auto const target_time = std::chrono::time_point_cast<std::chrono::seconds>(now) + 1s + 10ms;
auto target_interval = target_time - now;
if (target_interval < 100ms)