mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-04 07:27:26 +01:00
Problem: use of std::map::insert is inefficient
Solution: use std::map::emplace instead, where available
This commit is contained in:
parent
07eb52cbad
commit
a4aceb272b
@ -451,7 +451,8 @@ int zmq::ctx_t::register_endpoint (const char *addr_,
|
||||
{
|
||||
scoped_lock_t locker(endpoints_sync);
|
||||
|
||||
const bool inserted = endpoints.insert (endpoints_t::value_type (std::string (addr_), endpoint_)).second;
|
||||
const bool inserted = endpoints.ZMQ_MAP_INSERT_OR_EMPLACE (addr_,
|
||||
endpoint_).second;
|
||||
if (!inserted) {
|
||||
errno = EADDRINUSE;
|
||||
return -1;
|
||||
@ -524,7 +525,7 @@ void zmq::ctx_t::pend_connection (const std::string &addr_,
|
||||
if (it == endpoints.end ()) {
|
||||
// Still no bind.
|
||||
endpoint_.socket->inc_seqnum ();
|
||||
pending_connections.insert (pending_connections_t::value_type (addr_, pending_connection));
|
||||
pending_connections.ZMQ_MAP_INSERT_OR_EMPLACE (addr_, pending_connection);
|
||||
} else {
|
||||
// Bind has happened in the mean time, connect directly
|
||||
connect_inproc_sockets(it->second.socket, it->second.options, pending_connection, connect_side);
|
||||
|
@ -62,8 +62,8 @@ void zmq::mechanism_t::peer_routing_id (msg_t *msg_)
|
||||
void zmq::mechanism_t::set_user_id (const void *data_, size_t size_)
|
||||
{
|
||||
user_id.set (static_cast <const unsigned char*> (data_), size_);
|
||||
zap_properties.insert (metadata_t::dict_t::value_type (
|
||||
ZMQ_MSG_PROPERTY_USER_ID, std::string ((char *) data_, size_)));
|
||||
zap_properties.ZMQ_MAP_INSERT_OR_EMPLACE (
|
||||
ZMQ_MSG_PROPERTY_USER_ID, std::string ((char *) data_, size_));
|
||||
}
|
||||
|
||||
const zmq::blob_t &zmq::mechanism_t::get_user_id () const
|
||||
@ -218,13 +218,11 @@ int zmq::mechanism_t::parse_metadata (const unsigned char *ptr_,
|
||||
return -1;
|
||||
}
|
||||
if (zap_flag)
|
||||
zap_properties.insert (
|
||||
metadata_t::dict_t::value_type (
|
||||
name, std::string ((char *) value, value_length)));
|
||||
zap_properties.ZMQ_MAP_INSERT_OR_EMPLACE (
|
||||
name, std::string ((char *) value, value_length));
|
||||
else
|
||||
zmtp_properties.insert (
|
||||
metadata_t::dict_t::value_type (
|
||||
name, std::string ((char *) value, value_length)));
|
||||
zmtp_properties.ZMQ_MAP_INSERT_OR_EMPLACE (
|
||||
name, std::string ((char *) value, value_length));
|
||||
}
|
||||
if (bytes_left > 0) {
|
||||
errno = EPROTO;
|
||||
|
@ -206,7 +206,7 @@ void zmq::pgm_receiver_t::in_event ()
|
||||
// New peer. Add it to the list of know but unjoint peers.
|
||||
if (it == peers.end ()) {
|
||||
peer_info_t peer_info = {false, NULL};
|
||||
it = peers.insert (peers_t::value_type (*tsi, peer_info)).first;
|
||||
it = peers.ZMQ_MAP_INSERT_OR_EMPLACE (*tsi, peer_info).first;
|
||||
}
|
||||
|
||||
insize = static_cast <size_t> (received);
|
||||
|
@ -76,7 +76,7 @@ void zmq::radio_t::xread_activated (pipe_t *pipe_)
|
||||
std::string group = std::string (msg.group ());
|
||||
|
||||
if (msg.is_join ())
|
||||
subscriptions.insert (subscriptions_t::value_type (group, pipe_));
|
||||
subscriptions.ZMQ_MAP_INSERT_OR_EMPLACE (ZMQ_MOVE(group), pipe_);
|
||||
else {
|
||||
std::pair<subscriptions_t::iterator, subscriptions_t::iterator> range =
|
||||
subscriptions.equal_range (group);
|
||||
|
@ -61,7 +61,7 @@ void zmq::server_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
|
||||
pipe_->set_server_socket_routing_id (routing_id);
|
||||
// Add the record into output pipes lookup table
|
||||
outpipe_t outpipe = {pipe_, true};
|
||||
bool ok = outpipes.insert (outpipes_t::value_type (routing_id, outpipe)).second;
|
||||
bool ok = outpipes.ZMQ_MAP_INSERT_OR_EMPLACE (routing_id, outpipe).second;
|
||||
zmq_assert (ok);
|
||||
|
||||
fq.attach (pipe_);
|
||||
|
@ -817,7 +817,7 @@ int zmq::socket_base_t::connect (const char *addr_)
|
||||
last_endpoint.assign (addr_);
|
||||
|
||||
// remember inproc connections for disconnect
|
||||
inprocs.insert (inprocs_t::value_type (std::string (addr_), new_pipes [0]));
|
||||
inprocs.ZMQ_MAP_INSERT_OR_EMPLACE (addr_, new_pipes [0]);
|
||||
|
||||
options.connected = true;
|
||||
return 0;
|
||||
@ -1004,7 +1004,7 @@ void zmq::socket_base_t::add_endpoint (const char *addr_, own_t *endpoint_, pipe
|
||||
{
|
||||
// Activate the session. Make it a child of this socket.
|
||||
launch_child (endpoint_);
|
||||
endpoints.insert (endpoints_t::value_type (std::string (addr_), endpoint_pipe_t (endpoint_, pipe)));
|
||||
endpoints.ZMQ_MAP_INSERT_OR_EMPLACE (addr_, endpoint_pipe_t (endpoint_, pipe));
|
||||
}
|
||||
|
||||
int zmq::socket_base_t::term_endpoint (const char *addr_)
|
||||
|
@ -1010,14 +1010,14 @@ void zmq::stream_engine_t::set_handshake_timer ()
|
||||
|
||||
bool zmq::stream_engine_t::init_properties (properties_t & properties) {
|
||||
if (peer_address.empty()) return false;
|
||||
properties.insert (
|
||||
std::make_pair (ZMQ_MSG_PROPERTY_PEER_ADDRESS, peer_address));
|
||||
properties.ZMQ_MAP_INSERT_OR_EMPLACE (
|
||||
ZMQ_MSG_PROPERTY_PEER_ADDRESS, peer_address);
|
||||
|
||||
// Private property to support deprecated SRCFD
|
||||
std::ostringstream stream;
|
||||
stream << (int)s;
|
||||
std::string fd_string = stream.str();
|
||||
properties.insert(std::make_pair("__fd", fd_string));
|
||||
properties.ZMQ_MAP_INSERT_OR_EMPLACE ("__fd", ZMQ_MOVE(fd_string));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user