Skip to content

Commit 50dbce9

Browse files
theotherjimmyBogdan Marinescu
authored andcommitted
Fixes to function caching in targets.py
Now funnctions are looked up in the cache using a (function name, arguments) key, which makes it possible to cache different invocations of the functions (with different arguments). Also applied the @cached attribute to get_target.
1 parent 4b441c9 commit 50dbce9

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

tools/targets.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,16 @@ class HookError(Exception):
4848
caches = {}
4949
def cached(func):
5050
def wrapper(*args, **kwargs):
51-
if not caches.has_key(func):
52-
caches[func] = func(*args, **kwargs)
53-
return caches[func]
51+
if not caches.has_key((func.__name__, args)):
52+
caches[(func.__name__, args)] = func(*args, **kwargs)
53+
return caches[(func.__name__, args)]
5454
return wrapper
5555

5656
class Target:
5757
# Cumulative attributes can have values appended to them, so they
5858
# need to be computed differently than regular attributes
5959
__cumulative_attributes = ['extra_labels', 'macros', 'device_has', 'features']
6060

61-
# {target_name: target_instance} map for all the targets in the system
62-
__target_map = {}
63-
6461
# List of targets that were added dynamically using "add_py_targets" (see below)
6562
__py_targets = set()
6663

@@ -200,10 +197,9 @@ def add_py_targets(new_targets):
200197

201198
# Return the target instance starting from the target name
202199
@staticmethod
200+
@cached
203201
def get_target(name):
204-
if not Target.__target_map.has_key(name):
205-
Target.__target_map[name] = Target(name)
206-
return Target.__target_map[name]
202+
return Target(name)
207203

208204
def __init__(self, name):
209205
self.name = name

0 commit comments

Comments
 (0)