浏览代码

Cosmetics

Ask Solem 12 年之前
父节点
当前提交
0d4112b6a4
共有 1 个文件被更改,包括 7 次插入13 次删除
  1. 7 13
      celery/utils/functional.py

+ 7 - 13
celery/utils/functional.py

@@ -55,19 +55,13 @@ class LRUCache(UserDict):
 
     def update(self, *args, **kwargs):
         with self.mutex:
-            self.data.update(*args, **kwargs)
-
-            if not self.limit:
-                return
-
-            # pop additional items if dict growed too much
-            i = iter(self.data)  # start from bottom (LRU)
-            overflow = len(self.data) - self.limit
-
-            # negative overflow will lead to an empty list
-            to_pop = [next(i) for _ in xrange(overflow)]
-            for item in to_pop:
-                self.data.pop(item)
+            data, limit = self.data, self.limit
+            data.update(*args, **kwargs)
+            if limit and len(data) > limit:
+                # pop additional items in case limit exceeded
+                # negative overflow will lead to an empty list
+                for item in islice(iter(data), len(data) - limit):
+                    data.pop(item)
 
     def __setitem__(self, key, value):
         # remove least recently used key.