diff options
author | Steven Knight <knight@baldmt.com> | 2005-05-31 19:18:42 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-05-31 19:18:42 (GMT) |
commit | e21fab68f13999f4e0051ce75977f9c395940b6f (patch) | |
tree | 1f255b4f5b45cd2bdac85713977aed62a4da4f02 | |
parent | 883dffbfbd1f02b6eaa7f4adf505b01392c1c008 (diff) | |
download | SCons-e21fab68f13999f4e0051ce75977f9c395940b6f.zip SCons-e21fab68f13999f4e0051ce75977f9c395940b6f.tar.gz SCons-e21fab68f13999f4e0051ce75977f9c395940b6f.tar.bz2 |
Speed up md5 collection of build signature calculations.
-rw-r--r-- | src/engine/SCons/Sig/MD5.py | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/engine/SCons/Sig/MD5.py b/src/engine/SCons/Sig/MD5.py index 2adcee0..501fec4 100644 --- a/src/engine/SCons/Sig/MD5.py +++ b/src/engine/SCons/Sig/MD5.py @@ -49,26 +49,30 @@ def current(new, old): """ return new == old -def hexdigest(s): - """Return a signature as a string of hex characters. - """ - # NOTE: This routine is a method in the Python 2.0 interface - # of the native md5 module, but we want SCons to operate all - # the way back to at least Python 1.5.2, which doesn't have it. - h = string.hexdigits - r = '' - for c in s: - i = ord(c) - r = r + h[(i >> 4) & 0xF] + h[i & 0xF] - return r - try: - a = md5.new('test').hexdigest() + md5.new('').hexdigest except AttributeError: - md5sig = lambda c: hexdigest(md5.new(str(c)).digest()) -else: - md5sig = lambda c: md5.new(str(c)).hexdigest() + # The md5 objects created by the module have no native hexdigest() + # method (*cough* 1.5.2 *cough*) so provide an equivalent. + class new_md5: + def __init__(self, s): + self.m = md5.new(str(s)) + #def copy(self): + # return self.m.copy() + def digest(self): + return self.m.digest() + def hexdigest(self): + h = string.hexdigits + r = '' + for c in self.m.digest(): + i = ord(c) + r = r + h[(i >> 4) & 0xF] + h[i & 0xF] + return r + def update(self, s): + return self.m.update(s) +else: + new_md5 = lambda s: md5.new(str(s)) def collect(signatures): """ @@ -78,10 +82,9 @@ def collect(signatures): returns - the aggregate signature """ if len(signatures) == 1: - return signatures[0] + return signatures[0] else: - contents = string.join(signatures, ', ') - return hexdigest(md5.new(contents).digest()) + return new_md5(string.join(signatures, ', ')).hexdigest() def signature(obj): """Generate a signature for an object @@ -90,7 +93,7 @@ def signature(obj): gc = obj.get_contents except AttributeError: raise AttributeError, "unable to fetch contents of '%s'" % str(obj) - return md5sig(gc()) + return new_md5(gc()).hexdigest() def to_string(signature): """Convert a signature to a string""" |