diff options
author | Guido van Rossum <guido@python.org> | 2000-03-28 21:42:38 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-03-28 21:42:38 (GMT) |
commit | 1916b35f5864b2bfe5e2687b7db4fc0c329c9402 (patch) | |
tree | 090f73a5814f9b21764bc479b732bc42fdfb1cda | |
parent | 8f11d8e52ee8457e250d9f96e14327adf40d0855 (diff) | |
download | cpython-1916b35f5864b2bfe5e2687b7db4fc0c329c9402.zip cpython-1916b35f5864b2bfe5e2687b7db4fc0c329c9402.tar.gz cpython-1916b35f5864b2bfe5e2687b7db4fc0c329c9402.tar.bz2 |
Fredrik Lundh:
The new filecmp module has an optional argument called use_statcache
which is documented as a true/false value, but used as an tuple index.
This patches replaces the tuple stuff with a good old if- statement,
and also removes a few other tuple pack/unpack constructs (if not
else, this saves a few bytes in the PYC file, and a few microseconds
when using the module ;-).
-rw-r--r-- | Lib/filecmp.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/Lib/filecmp.py b/Lib/filecmp.py index e1a30bc..24ae4b3 100644 --- a/Lib/filecmp.py +++ b/Lib/filecmp.py @@ -30,14 +30,21 @@ def cmp(f1, f2, shallow=1,use_statcache=0): and the cache will never grow stale. """ - stat_function = (os.stat, statcache.stat)[use_statcache] - s1, s2 = _sig(stat_function(f1)), _sig(stat_function(f2)) - if s1[0]!=stat.S_IFREG or s2[0]!=stat.S_IFREG: return 0 - if shallow and s1 == s2: return 1 - if s1[1]!=s2[1]: return 0 + if use_statcache: + stat_function = statcache.stat + else: + stat_function = os.stat + s1 = _sig(stat_function(f1)) + s2 = _sig(stat_function(f2)) + if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG: + return 0 + if shallow and s1 == s2: + return 1 + if s1[1] != s2[1]: + return 0 result = _cache.get((f1, f2)) - if result and (s1, s2)==result[:2]: + if result and (s1, s2) == result[:2]: return result[2] outcome = _do_cmp(f1, f2) _cache[f1, f2] = s1, s2, outcome @@ -50,8 +57,12 @@ def _sig(st): def _do_cmp(f1, f2): bufsize = BUFSIZE - fp1 , fp2 = open(f1, 'rb'), open(f2, 'rb') + fp1 = open(f1, 'rb') + fp2 = open(f2, 'rb') while 1: - b1, b2 = fp1.read(bufsize), fp2.read(bufsize) - if b1!=b2: return 0 - if not b1: return 1 + b1 = fp1.read(bufsize) + b2 = fp2.read(bufsize) + if b1 != b2: + return 0 + if not b1: + return 1 |