From ca8be7d9bf09c64a9fc13293e4289fc174b728c4 Mon Sep 17 00:00:00 2001 From: githejie Date: Sat, 3 Aug 2024 12:15:36 +0800 Subject: [PATCH] Enable emplace feature for timers --- src/timers.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/timers.cpp b/src/timers.cpp index 0aeb7befe9..56e74e2215 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -2,6 +2,7 @@ #include "precompiled.hpp" #include "timers.hpp" +#include "blob.hpp" #include "err.hpp" #include @@ -30,7 +31,7 @@ int zmq::timers_t::add (size_t interval_, timers_timer_fn handler_, void *arg_) uint64_t when = _clock.now_ms () + interval_; timer_t timer = {++_next_timer_id, interval_, handler_, arg_}; - _timers.insert (timersmap_t::value_type (when, timer)); + _timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer); return timer.timer_id; } @@ -79,7 +80,7 @@ int zmq::timers_t::set_interval (int timer_id_, size_t interval_) timer.interval = interval_; uint64_t when = _clock.now_ms () + interval_; _timers.erase (it); - _timers.insert (timersmap_t::value_type (when, timer)); + _timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer); return 0; } @@ -97,7 +98,7 @@ int zmq::timers_t::reset (int timer_id_) timer_t timer = it->second; uint64_t when = _clock.now_ms () + timer.interval; _timers.erase (it); - _timers.insert (timersmap_t::value_type (when, timer)); + _timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer); return 0; } @@ -147,8 +148,7 @@ int zmq::timers_t::execute () timer.handler (timer.timer_id, timer.arg); - _timers.insert ( - timersmap_t::value_type (now + timer.interval, timer)); + _timers.ZMQ_MAP_INSERT_OR_EMPLACE (now + timer.interval, timer); } } _timers.erase (begin, it);