Browse Source

[2856] Use deque instead of a list to store events

... for faster pops from position 0 of the list.
Mukund Sivaraman 12 years ago
parent
commit
724e39ef6e
1 changed files with 4 additions and 5 deletions
  1. 4 5
      src/lib/python/isc/memmgr/datasrc_info.py

+ 4 - 5
src/lib/python/isc/memmgr/datasrc_info.py

@@ -14,6 +14,7 @@
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 import os
+from collections import deque
 
 class SegmentInfoError(Exception):
     """An exception raised for general errors in the SegmentInfo class."""
@@ -83,7 +84,7 @@ class SegmentInfo:
         # READY state. This maintains such pending events in the order
         # they arrived. SegmentInfo doesn't have to know the details of
         # the stored data; it only matters for the memmgr.
-        self.__events = []
+        self.__events = deque()
 
     def get_state(self):
         """Returns the state of SegmentInfo (UPDATING, SYNCHRONIZING,
@@ -104,7 +105,7 @@ class SegmentInfo:
 
     def get_events(self):
         """Returns a list of pending events in the order they arrived."""
-        return self.__events
+        return list(self.__events)
 
     # Helper method used in complete_update(), sync_reader() and
     # remove_reader().
@@ -112,9 +113,7 @@ class SegmentInfo:
         if not self.__old_readers:
             self.__state = new_state
             if self.__events:
-                e = self.__events[0]
-                del self.__events[0]
-                return e
+                return self.__events.popleft()
 
         return None