]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2856] Use deque instead of a list to store events
authorMukund Sivaraman <muks@isc.org>
Wed, 24 Jul 2013 09:39:54 +0000 (15:09 +0530)
committerMukund Sivaraman <muks@isc.org>
Wed, 24 Jul 2013 09:41:51 +0000 (15:11 +0530)
... for faster pops from position 0 of the list.

src/lib/python/isc/memmgr/datasrc_info.py

index 65502e350af7ed6e4ca4c07123f05ad585485f40..84d8bb46d8b677e256ae3184b08570ccf2aead2d 100644 (file)
@@ -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