Browse Source

[2856] Test lists and sets directly instead of using len()

Mukund Sivaraman 12 years ago
parent
commit
e61c29836e

+ 2 - 2
src/lib/python/isc/memmgr/builder.py

@@ -144,7 +144,7 @@ class MemorySegmentBuilder:
         # Acquire the condition variable while running the loop.
         # Acquire the condition variable while running the loop.
         with self._cv:
         with self._cv:
             while not self._shutdown:
             while not self._shutdown:
-                while len(self._command_queue) == 0:
+                while not self._command_queue:
                     self._cv.wait()
                     self._cv.wait()
                 # Move the queue content to a local queue. Be careful of
                 # Move the queue content to a local queue. Be careful of
                 # not making assignments to reference variables.
                 # not making assignments to reference variables.
@@ -176,6 +176,6 @@ class MemorySegmentBuilder:
                 # Notify (any main thread) on the socket about a
                 # Notify (any main thread) on the socket about a
                 # response. Otherwise, the main thread may wait in its
                 # response. Otherwise, the main thread may wait in its
                 # loop without knowing there was a problem.
                 # loop without knowing there was a problem.
-                if len(self._response_queue) > 0:
+                if self._response_queue:
                     while self._sock.send(b'x') != 1:
                     while self._sock.send(b'x') != 1:
                         continue
                         continue

+ 3 - 3
src/lib/python/isc/memmgr/datasrc_info.py

@@ -109,9 +109,9 @@ class SegmentInfo:
     # Helper method used in complete_update(), sync_reader() and
     # Helper method used in complete_update(), sync_reader() and
     # remove_reader().
     # remove_reader().
     def __sync_reader_helper(self, new_state):
     def __sync_reader_helper(self, new_state):
-        if len(self.__old_readers) == 0:
+        if not self.__old_readers:
             self.__state = new_state
             self.__state = new_state
-            if len(self.__events) > 0:
+            if self.__events:
                 e = self.__events[0]
                 e = self.__events[0]
                 del self.__events[0]
                 del self.__events[0]
                 return e
                 return e
@@ -145,7 +145,7 @@ class SegmentInfo:
         event (without removing it from the pending events queue). This
         event (without removing it from the pending events queue). This
         tells the caller (memmgr) that it should initiate the update
         tells the caller (memmgr) that it should initiate the update
         process with the builder. In all other cases it returns None."""
         process with the builder. In all other cases it returns None."""
-        if self.__state == self.READY and  len(self.__events) > 0:
+        if self.__state == self.READY and self.__events:
             self.__state = self.UPDATING
             self.__state = self.UPDATING
             return self.__events[0]
             return self.__events[0]