Browse Source

don't call a function excessively...

setdefault works best for simple data types, calling the factory
function every time doesn't make sense...
main
John-Mark Gurney 1 year ago
parent
commit
df16a93fe1
1 changed files with 5 additions and 2 deletions
  1. +5
    -2
      ui/medashare/btv/__init__.py

+ 5
- 2
ui/medashare/btv/__init__.py View File

@@ -196,8 +196,11 @@ def validate(torrent, basedir, with_file_hashes=None):

def apply_fun(data, fname, offset):
if with_file_hashes is not None:
hashobj, curoff = file_hashes.setdefault(fname,
(with_file_hashes(), 0))
try:
hashobj, curoff = file_hashes[fname]
except KeyError:
hashobj, curoff = with_file_hashes(), 0
file_hashes[fname] = hashobj, curoff

if curoff == offset:
hashobj.update(data)


Loading…
Cancel
Save