Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7079719

Browse files
committed
Issue 11802: filecmp cache was growing without bound.
1 parent 6ddefd7 commit 7079719

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Lib/filecmp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ def cmp(f1, f2, shallow=True):
4848
if s1[1] != s2[1]:
4949
return False
5050

51-
result = _cache.get((f1, f2))
52-
if result and (s1, s2) == result[:2]:
53-
return result[2]
54-
outcome = _do_cmp(f1, f2)
55-
_cache[f1, f2] = s1, s2, outcome
51+
outcome = _cache.get((f1, f2, s1, s2))
52+
if outcome is None:
53+
outcome = _do_cmp(f1, f2)
54+
if len(_cache) > 100: # limit the maximum size of the cache
55+
_cache.clear()
56+
_cache[f1, f2, s1, s2] = outcome
5657
return outcome
5758

5859
def _sig(st):

0 commit comments

Comments
 (0)