[Python-checkins] cpython (2.7): Issue 11802: filecmp cache was growing without bound.

raymond.hettinger python-checkins at python.org
Sat Jun 25 17:14:59 CEST 2011


http://hg.python.org/cpython/rev/11568c59d9d4
changeset:   70976:11568c59d9d4
branch:      2.7
parent:      70973:68bc3c5960a4
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Jun 25 17:14:53 2011 +0200
summary:
  Issue 11802:  filecmp cache was growing without bound.

files:
  Lib/filecmp.py |  11 ++++++-----
  Misc/NEWS      |   3 +++
  2 files changed, 9 insertions(+), 5 deletions(-)


diff --git a/Lib/filecmp.py b/Lib/filecmp.py
--- a/Lib/filecmp.py
+++ b/Lib/filecmp.py
@@ -48,11 +48,12 @@
     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):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,9 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list