]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 11802: filecmp cache was growing without bound.
authorRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 15:20:21 +0000 (17:20 +0200)
committerRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 15:20:21 +0000 (17:20 +0200)
Lib/filecmp.py

index e5983cd776947cb57272e3a97fdd07ec708d716f..f5cea1de6ff02639711f9c6e466c6f4ba6d086ca 100644 (file)
@@ -48,11 +48,12 @@ def cmp(f1, f2, shallow=True):
     if s1[1] != s2[1]:
         return False
 
-    result = _cache.get((f1, f2))
-    if result and (s1, s2) == result[:2]:
-        return result[2]
-    outcome = _do_cmp(f1, f2)
-    _cache[f1, f2] = s1, s2, outcome
+    outcome = _cache.get((f1, f2, s1, s2))
+    if outcome is None:
+        outcome = _do_cmp(f1, f2)
+        if len(_cache) > 100:      # limit the maximum size of the cache
+            _cache.clear()
+        _cache[f1, f2, s1, s2] = outcome
     return outcome
 
 def _sig(st):