Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 9097:431462bd8478
fix memory usage of revlog caches by limiting cache size [issue1639]
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 09 Jul 2009 17:10:07 -0500 |
parents | 8ec39725d966 |
children | bbc78cb1bf15 7116494c48ab |
comparison
equal
deleted
inserted
replaced
9096:47bc92755b95 | 9097:431462bd8478 |
---|---|
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): |