]> granicus.if.org Git - python/commitdiff
Issue 11802: filecmp cache was growing without bound.
authorRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 15:14:53 +0000 (17:14 +0200)
committerRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 15:14:53 +0000 (17:14 +0200)
Lib/filecmp.py
Misc/NEWS

index 89a48359a2f4f14ca814a626ad638e7c20714add..4728317fce9934b5ef7cbe7fb36b740c6d12bce0 100644 (file)
@@ -48,11 +48,12 @@ def cmp(f1, f2, shallow=1):
     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):
index bddddfa29cdf573deba351eff3cd8666feb898db..9e0b8f4b8f151984f3b15bf742bca31f17fc838b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #11802:  The cache in filecmp now has a maximum size of 100 so that
+  it won't grow without bound.
+
 - Issue #12404: Remove C89 incompatible code from mmap module. Patch by Akira
   Kitada.