Mercurial > hg
comparison mercurial/util.py @ 9102:bbc78cb1bf15
Merge with stable
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 09 Jul 2009 19:49:02 -0500 |
parents | 6cf043b1aa14 431462bd8478 |
children | 54eb3782d32f |
comparison
equal
deleted
inserted
replaced
9092:9aebeea7ac00 | 9102:bbc78cb1bf15 |
---|---|
109 return cache[arg] | 109 return cache[arg] |
110 else: | 110 else: |
111 def f(*args): | 111 def f(*args): |
112 if args not in cache: | 112 if args not in cache: |
113 cache[args] = func(*args) | 113 cache[args] = func(*args) |
114 return cache[args] | |
115 | |
116 return f | |
117 | |
118 def lrucachefunc(func): | |
119 '''cache most recent results of function calls''' | |
120 cache = {} | |
121 order = [] | |
122 if func.func_code.co_argcount == 1: | |
123 def f(arg): | |
124 if arg not in cache: | |
125 if len(cache) > 20: | |
126 del cache[order.pop(0)] | |
127 cache[arg] = func(arg) | |
128 else: | |
129 order.remove(arg) | |
130 order.append(arg) | |
131 return cache[arg] | |
132 else: | |
133 def f(*args): | |
134 if args not in cache: | |
135 if len(cache) > 20: | |
136 del cache[order.pop(0)] | |
137 cache[args] = func(*args) | |
138 else: | |
139 order.remove(args) | |
140 order.append(args) | |
114 return cache[args] | 141 return cache[args] |
115 | 142 |
116 return f | 143 return f |
117 | 144 |
118 class propertycache(object): | 145 class propertycache(object): |