Use vectors for storage in Poller
[libs/core.git] / source / io / unix / poll.cpp
index 6272b4dbf143e26aba3331117e284d1b690dbac7..0fb9d22e03919476e95d52e09ca5faf10088241f 100644 (file)
@@ -57,17 +57,24 @@ namespace IO {
 
 void Poller::rebuild_array()
 {
-       priv->pfd.clear();
+       if(objs_changed)
+       {
+               priv->pfd.clear();
+               priv->pfd.reserve(objects.size());
 
-       for(EventMap::iterator i=objects.begin(); i!=objects.end(); ++i)
+               for(vector<Slot>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+               {
+                       pollfd p;
+                       p.fd = *i->object->get_event_handle();
+                       p.events = sys_poll_event(i->events);
+                       priv->pfd.push_back(p);
+               }
+       }
+       else
        {
-               pollfd p;
-               p.fd = *i->first->get_event_handle();
-               p.events = sys_poll_event(i->second);
-               priv->pfd.push_back(p);
+               for(unsigned i=0; i<objects.size(); ++i)
+                       priv->pfd[i].events = sys_poll_event(objects[i].events);
        }
-
-       objs_changed = false;
 }
 
 void Poller::platform_poll(int timeout)
@@ -81,11 +88,10 @@ void Poller::platform_poll(int timeout)
                        throw system_error("poll");
        }
 
-       EventMap::iterator j = objects.begin();
-       for(vector<pollfd>::iterator i=priv->pfd.begin(); (i!=priv->pfd.end() && ret>0); ++i, ++j)
-               if(i->revents)
+       for(unsigned i=0; (i<objects.size() && ret>0); ++i)
+               if(priv->pfd[i].revents)
                {
-                       poll_result.push_back(Slot(j->first, poll_event_from_sys(i->revents)));
+                       poll_result.push_back(Slot(objects[i].object, poll_event_from_sys(priv->pfd[i].revents)));
                        --ret;
                }
 }