2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-14 00:32:11 +00:00

Add decorator for caching function results.

[SVN r64350]
This commit is contained in:
Vladimir Prus
2010-07-26 08:07:07 +00:00
parent b5c0398989
commit 9859bcab15

View File

@@ -1,4 +1,5 @@
# Decorator the specifies bjam-side prototype for a Python function
def bjam_signature(s):
def wrap(f):
@@ -6,3 +7,23 @@ def bjam_signature(s):
return f
return wrap
class cached(object):
def __init__(self, function):
self.function = function
self.cache = {}
def __call__(self, *args):
try:
return self.cache[args]
except KeyError:
v = self.function(*args)
self.cache[args] = v
return v
def unquote(s):
if s and s[0] == '"' and s[-1] == '"':
return s[1:-1]
else:
return s