From: stevenknight Date: Tue, 31 May 2005 19:18:42 +0000 (+0000) Subject: Speed up md5 collection of build signature calculations. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=175a7b5933621147313fa0bf8f073a0d942c01fb;p=scons.git Speed up md5 collection of build signature calculations. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1302 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Sig/MD5.py b/src/engine/SCons/Sig/MD5.py index 2adcee09..501fec4b 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"""