Skip to content

Commit c0a6f96

Browse files
committed
Replace insert with emplace
To avoid unnecessary copy construction or move construction.
1 parent 59c9122 commit c0a6f96

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/options.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,7 @@ int zmq::options_t::setsockopt (int option_,
758758
if (key.compare (0, 2, "X-") == 0
759759
&& key.length () <= UCHAR_MAX) {
760760
std::string val = s.substr (pos + 1, s.length ());
761-
app_metadata.insert (
762-
std::pair<std::string, std::string> (key, val));
761+
app_metadata.emplace (key, val);
763762
return 0;
764763
}
765764
}

src/poller_base.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void zmq::poller_base_t::add_timer (int timeout_, i_poll_events *sink_, int id_)
2828
{
2929
uint64_t expiration = _clock.now_ms () + timeout_;
3030
timer_info_t info = {sink_, id_};
31-
_timers.insert (timers_t::value_type (expiration, info));
31+
_timers.emplace (expiration, info);
3232
}
3333

3434
void zmq::poller_base_t::cancel_timer (i_poll_events *sink_, int id_)

src/timers.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ int zmq::timers_t::add (size_t interval_, timers_timer_fn handler_, void *arg_)
3030

3131
uint64_t when = _clock.now_ms () + interval_;
3232
timer_t timer = {++_next_timer_id, interval_, handler_, arg_};
33-
_timers.insert (timersmap_t::value_type (when, timer));
33+
_timers.emplace (when, timer);
3434

3535
return timer.timer_id;
3636
}
@@ -79,7 +79,7 @@ int zmq::timers_t::set_interval (int timer_id_, size_t interval_)
7979
timer.interval = interval_;
8080
uint64_t when = _clock.now_ms () + interval_;
8181
_timers.erase (it);
82-
_timers.insert (timersmap_t::value_type (when, timer));
82+
_timers.emplace (when, timer);
8383

8484
return 0;
8585
}
@@ -97,7 +97,7 @@ int zmq::timers_t::reset (int timer_id_)
9797
timer_t timer = it->second;
9898
uint64_t when = _clock.now_ms () + timer.interval;
9999
_timers.erase (it);
100-
_timers.insert (timersmap_t::value_type (when, timer));
100+
_timers.emplace (when, timer);
101101

102102
return 0;
103103
}
@@ -147,8 +147,7 @@ int zmq::timers_t::execute ()
147147

148148
timer.handler (timer.timer_id, timer.arg);
149149

150-
_timers.insert (
151-
timersmap_t::value_type (now + timer.interval, timer));
150+
_timers.emplace (now + timer.interval, timer);
152151
}
153152
}
154153
_timers.erase (begin, it);

0 commit comments

Comments
 (0)