[bitbake-devel,2/2] bb/utils.py: implement (md5, sha1, sha256)_file in terms of hash_file

Submitted by Rasmus Villemoes on July 10, 2018, 2:06 p.m. | Patch ID: 152517

Details

Message ID 20180710140612.26245-2-rasmus.villemoes@prevas.dk
State New
Headers show

Commit Message

Rasmus Villemoes July 10, 2018, 2:06 p.m.
Testing on the largest tarball in my downloads dir (linux-4.15.7.tar.xz)
shows that this is ~twice as fast for md5 and ~35% faster for sha256.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
 lib/bb/utils.py | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index cb7a6fa2..ef7fc932 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -547,12 +547,7 @@  def md5_file(filename):
     Return the hex string representation of the MD5 checksum of filename.
     """
     import hashlib
-    m = hashlib.md5()
-
-    with open(filename, "rb") as f:
-        for line in f:
-            m.update(line)
-    return m.hexdigest()
+    return hash_file(hashlib.md5(), filename).hexdigest()
 
 def sha256_file(filename):
     """
@@ -560,24 +555,14 @@  def sha256_file(filename):
     filename.
     """
     import hashlib
-
-    s = hashlib.sha256()
-    with open(filename, "rb") as f:
-        for line in f:
-            s.update(line)
-    return s.hexdigest()
+    return hash_file(hashlib.sha256(), filename).hexdigest()
 
 def sha1_file(filename):
     """
     Return the hex string representation of the SHA1 checksum of the filename
     """
     import hashlib
-
-    s = hashlib.sha1()
-    with open(filename, "rb") as f:
-        for line in f:
-            s.update(line)
-    return s.hexdigest()
+    return hash_file(hashlib.sha1(), filename).hexdigest()
 
 def preserved_envvars_exported():
     """Variables which are taken from the environment and placed in and exported