comparison mercurial/util.py @ 3147:97420a49188d

add comments in cachefunc
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Fri, 22 Sep 2006 17:58:22 +0200
parents e4ea47c21480
children 7492b33bdd9f
comparison
equal deleted inserted replaced
3146:e69a0cbe268e 3147:97420a49188d
24 class SignalInterrupt(Exception): 24 class SignalInterrupt(Exception):
25 """Exception raised on SIGTERM and SIGHUP.""" 25 """Exception raised on SIGTERM and SIGHUP."""
26 26
27 def cachefunc(func): 27 def cachefunc(func):
28 '''cache the result of function calls''' 28 '''cache the result of function calls'''
29 # XXX doesn't handle keywords args
29 cache = {} 30 cache = {}
30 if func.func_code.co_argcount == 1: 31 if func.func_code.co_argcount == 1:
32 # we gain a small amount of time because
33 # we don't need to pack/unpack the list
31 def f(arg): 34 def f(arg):
32 if arg not in cache: 35 if arg not in cache:
33 cache[arg] = func(arg) 36 cache[arg] = func(arg)
34 return cache[arg] 37 return cache[arg]
35 else: 38 else: