changeset 8281:3e1e499db9d7

util: initialize md5 and sha1 without using extra global variables This lets the functions skip the "if _sha1 is None" test on each call.
author Martin Geisler <mg@lazybytes.net>
date Sun, 03 May 2009 00:03:35 +0200
parents 0b02d98d44d0
children c214a895f62c
files mercurial/util.py
diffstat 1 files changed, 16 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Sat May 02 23:05:35 2009 +0200
+++ b/mercurial/util.py	Sun May 03 00:03:35 2009 +0200
@@ -20,28 +20,26 @@
 
 # Python compatibility
 
-_md5 = None
 def md5(s):
-    global _md5
-    if _md5 is None:
-        try:
-            import hashlib
-            _md5 = hashlib.md5
-        except ImportError:
-            import md5
-            _md5 = md5.md5
+    try:
+        import hashlib
+        _md5 = hashlib.md5
+    except ImportError:
+        import md5
+        _md5 = md5.md5
+    global md5
+    md5 = _md5
     return _md5(s)
 
-_sha1 = None
 def sha1(s):
-    global _sha1
-    if _sha1 is None:
-        try:
-            import hashlib
-            _sha1 = hashlib.sha1
-        except ImportError:
-            import sha
-            _sha1 = sha.sha
+    try:
+        import hashlib
+        _sha1 = hashlib.sha1
+    except ImportError:
+        import sha
+        _sha1 = sha.sha
+    global sha1
+    sha1 = _sha1
     return _sha1(s)
 
 import subprocess