From dd7cd28097a1794e7e6f23132f5dbafe9c356f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrer=20=C3=96zen?= Date: Fri, 2 Mar 2007 08:41:42 +0000 Subject: [PATCH] =?UTF-8?q?sha1=20hesaplamas=C4=B1n=C4=B1=20sat=C4=B1r=20y?= =?UTF-8?q?erine=20sabit=20bloklar=20=C3=BCzerinden=20yap.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bu yamayla hesaplamada %15 civarında bir hızlanma görülüyor. Heap peak aynı kalırken, heap total'de ciddi düşme var. Çeşitli dosyalar ve bir iki paketle denedim. Faik, uygunsa 2007 branch'ına da taşıyalım bunu. İlerde saçma try: except: kısmını da kaldırırsak olacak bu iş :) --- pisi/util.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pisi/util.py b/pisi/util.py index b134f653..e60dbb78 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -433,8 +433,19 @@ def sha1_file(filename): try: m = sha.new() f = file(filename, 'rb') - for line in f: - m.update(line) + while True: + # 256 KB seems ideal for speed/memory tradeoff + # It wont get much faster with bigger blocks, but + # heap peak grows + block = f.read(256 * 1024) + if len(block) == 0: + # end of file + break + m.update(block) + # Simple trick to keep total heap even lower + # Delete the previous block, so while next one is read + # we wont have two allocated blocks with same size + del block return m.hexdigest() except IOError: raise FileError(_("I/O Error: Cannot calculate SHA1 hash of %s") % filename)