summaryrefslogtreecommitdiffstats
path: root/Lib/filecmp.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-06-25 15:14:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-06-25 15:14:53 (GMT)
commit2c316a3e298b072f1f017cd3ba197905c43af926 (patch)
tree6ce8f1e219f00dd0d6c8154d25b75168af509689 /Lib/filecmp.py
parentfd1cb59618b6093d88a6c2f1ffea1656e87dfce3 (diff)
downloadcpython-2c316a3e298b072f1f017cd3ba197905c43af926.zip
cpython-2c316a3e298b072f1f017cd3ba197905c43af926.tar.gz
cpython-2c316a3e298b072f1f017cd3ba197905c43af926.tar.bz2
Issue 11802: filecmp cache was growing without bound.
Diffstat (limited to 'Lib/filecmp.py')
-rw-r--r--Lib/filecmp.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/filecmp.py b/Lib/filecmp.py
index 89a4835..4728317 100644
--- a/Lib/filecmp.py
+++ b/Lib/filecmp.py
@@ -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):