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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user