aboutsummaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index 6c3b90fb2..169e1218b 100644
--- a/utils.py
+++ b/utils.py
@@ -874,3 +874,17 @@ def rpathsHasOrigin(rpaths):
if match:
return True
return False
+
+def memoize(function):
+ """ Decorator to wrap a function with a memoizing callable.
+ It returns cached values when the wrapped function is called with the same arguments.
+ """
+ memo = {}
+ def wrapper(*args):
+ if args in memo:
+ return memo[args]
+ else:
+ rv = function(*args)
+ memo[args] = rv
+ return rv
+ return wrapper