Skip to content

Commit 72d2bc9

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

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/options.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <set>
77

88
#include "options.hpp"
9+
#include "blob.hpp"
910
#include "err.hpp"
1011
#include "macros.hpp"
1112

@@ -758,8 +759,7 @@ int zmq::options_t::setsockopt (int option_,
758759
if (key.compare (0, 2, "X-") == 0
759760
&& key.length () <= UCHAR_MAX) {
760761
std::string val = s.substr (pos + 1, s.length ());
761-
app_metadata.insert (
762-
std::pair<std::string, std::string> (key, val));
762+
app_metadata.ZMQ_MAP_INSERT_OR_EMPLACE (key, val);
763763
return 0;
764764
}
765765
}

src/poller_base.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "precompiled.hpp"
44
#include "poller_base.hpp"
55
#include "i_poll_events.hpp"
6+
#include "blob.hpp"
67
#include "err.hpp"
78

89
zmq::poller_base_t::~poller_base_t ()
@@ -28,7 +29,7 @@ void zmq::poller_base_t::add_timer (int timeout_, i_poll_events *sink_, int id_)
2829
{
2930
uint64_t expiration = _clock.now_ms () + timeout_;
3031
timer_info_t info = {sink_, id_};
31-
_timers.insert (timers_t::value_type (expiration, info));
32+
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (expiration, info);
3233
}
3334

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

src/timers.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "precompiled.hpp"
44
#include "timers.hpp"
5+
#include "blob.hpp"
56
#include "err.hpp"
67

78
#include <algorithm>
@@ -30,7 +31,7 @@ int zmq::timers_t::add (size_t interval_, timers_timer_fn handler_, void *arg_)
3031

3132
uint64_t when = _clock.now_ms () + interval_;
3233
timer_t timer = {++_next_timer_id, interval_, handler_, arg_};
33-
_timers.insert (timersmap_t::value_type (when, timer));
34+
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer);
3435

3536
return timer.timer_id;
3637
}
@@ -79,7 +80,7 @@ int zmq::timers_t::set_interval (int timer_id_, size_t interval_)
7980
timer.interval = interval_;
8081
uint64_t when = _clock.now_ms () + interval_;
8182
_timers.erase (it);
82-
_timers.insert (timersmap_t::value_type (when, timer));
83+
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer);
8384

8485
return 0;
8586
}
@@ -97,7 +98,7 @@ int zmq::timers_t::reset (int timer_id_)
9798
timer_t timer = it->second;
9899
uint64_t when = _clock.now_ms () + timer.interval;
99100
_timers.erase (it);
100-
_timers.insert (timersmap_t::value_type (when, timer));
101+
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer);
101102

102103
return 0;
103104
}
@@ -147,8 +148,7 @@ int zmq::timers_t::execute ()
147148

148149
timer.handler (timer.timer_id, timer.arg);
149150

150-
_timers.insert (
151-
timersmap_t::value_type (now + timer.interval, timer));
151+
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (now + timer.interval, timer);
152152
}
153153
}
154154
_timers.erase (begin, it);

0 commit comments

Comments
 (0)