[Python-checkins] cpython (merge 3.2 -> default): Issue 11802: filecmp cache was growing without bound.

raymond.hettinger python-checkins at python.org
Sat Jun 25 17:21:29 CEST 2011


http://hg.python.org/cpython/rev/8f4466619e1c
changeset:   70978:8f4466619e1c
parent:      70975:fca745bc70be
parent:      70977:2bacaf6a80c4
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Jun 25 17:21:04 2011 +0200
summary:
  Issue 11802:  filecmp cache was growing without bound.

files:
  Lib/filecmp.py |  11 ++++++-----
  1 files changed, 6 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):

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


More information about the Python-checkins mailing list