summaryrefslogtreecommitdiff
path: root/src/app_thread.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@fastmq.commkdir>2009-09-02 16:16:25 +0200
committerMartin Sustrik <sustrik@fastmq.commkdir>2009-09-02 16:16:25 +0200
commit4914e5c9d192ac6763e5da6fa28ea503ee769bf0 (patch)
tree615b63ba64688584ef28c1ea564dff27ddd8b1af /src/app_thread.cpp
parentf92de9b2a9ad73fd7cd966e65b5a06b725e779fc (diff)
O(1) socket removal
Diffstat (limited to 'src/app_thread.cpp')
-rw-r--r--src/app_thread.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/app_thread.cpp b/src/app_thread.cpp
index e4e5b19..e108594 100644
--- a/src/app_thread.cpp
+++ b/src/app_thread.cpp
@@ -138,16 +138,16 @@ zmq::socket_base_t *zmq::app_thread_t::create_socket (int type_)
// TODO: type is ignored for the time being.
socket_base_t *s = new socket_base_t (this);
zmq_assert (s);
+ s->set_index (sockets.size ());
sockets.push_back (s);
return s;
}
void zmq::app_thread_t::remove_socket (socket_base_t *socket_)
{
- // TODO: To speed this up we can possibly use the system where each socket
- // holds its index (see I/O scheduler implementation).
- sockets_t::iterator it = std::find (sockets.begin (), sockets.end (),
- socket_);
- zmq_assert (it != sockets.end ());
- sockets.erase (it);
+ int i = socket_->get_index ();
+ socket_->set_index (-1);
+ sockets [i] = sockets.back ();
+ sockets [i]->set_index (i);
+ sockets.pop_back ();
}