diff options
author | jblum | 2009-01-11 07:57:08 +0000 |
---|---|---|
committer | jblum | 2009-01-11 07:57:08 +0000 |
commit | 509b112439807d9bc63d24adb5a248d9f81add91 (patch) | |
tree | 8e71de63b9198e425da142f556f66c362d93e2a1 /grc/src/platforms | |
parent | be1969eec0791ff97ab2fecf97e65fe92022e167 (diff) | |
download | gnuradio-509b112439807d9bc63d24adb5a248d9f81add91.tar.gz gnuradio-509b112439807d9bc63d24adb5a248d9f81add91.tar.bz2 gnuradio-509b112439807d9bc63d24adb5a248d9f81add91.zip |
cache evaluated statements, do not parse huge vectors for display
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10205 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src/platforms')
-rw-r--r-- | grc/src/platforms/gui/Param.py | 3 | ||||
-rw-r--r-- | grc/src/platforms/python/FlowGraph.py | 22 |
2 files changed, 21 insertions, 4 deletions
diff --git a/grc/src/platforms/gui/Param.py b/grc/src/platforms/gui/Param.py index 43265f274..7bc0d354f 100644 --- a/grc/src/platforms/gui/Param.py +++ b/grc/src/platforms/gui/Param.py @@ -118,7 +118,8 @@ class Param(Element): if self.is_enum(): dt_str = self.get_option(self.get_value()).get_name() elif isinstance(data, (list, tuple, set)): #vector types - dt_str = ', '.join(map(to_str, data)) + if len(data) > 8: dt_str = self.get_value() #large vectors use code + else: dt_str = ', '.join(map(to_str, data)) #small vectors use eval else: dt_str = to_str(data) #other types #truncate max_len = max(27 - len(self.get_name()), 3) diff --git a/grc/src/platforms/python/FlowGraph.py b/grc/src/platforms/python/FlowGraph.py index 6c9b7f642..cd5635b95 100644 --- a/grc/src/platforms/python/FlowGraph.py +++ b/grc/src/platforms/python/FlowGraph.py @@ -40,6 +40,22 @@ def get_variable_code(variable): class FlowGraph(_FlowGraph): + _eval_cache = dict() + def _eval(self, code, namespace): + """ + Evaluate the code with the given namespace. + @param code a string with python code + @param namespace a dict representing the namespace + @return the resultant object + """ + #check cache + if self._eval_cache.has_key(code) and self._eval_cache[code][0] == namespace: + return self._eval_cache[code][1] + #evaluate + result = eval(code, namespace, namespace) + self._eval_cache[code] = (namespace.copy(), result) + return result + def _get_io_signature(self, pad_key): """ Get an io signature for this flow graph. @@ -135,18 +151,18 @@ class FlowGraph(_FlowGraph): np = dict() for parameter in self.get_parameters(): try: - e = eval(parameter.get_param('value').to_code(), n, n) + e = self._eval(parameter.get_param('value').to_code(), n) np[parameter.get_id()] = e except: pass n.update(np) #merge param namespace #load variables for variable in self.get_variables(): try: - e = eval(get_variable_code(variable), n, n) + e = self._eval(get_variable_code(variable), n) n[variable.get_id()] = e except: pass #make namespace public self.n = n #evaluate - e = eval(expr, self.n, self.n) + e = self._eval(expr, self.n) return e |