commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10205 - in gnuradio/trunk/grc/src/platforms: gui pyth


From: jblum
Subject: [Commit-gnuradio] r10205 - in gnuradio/trunk/grc/src/platforms: gui python
Date: Sun, 11 Jan 2009 00:57:28 -0700 (MST)

Author: jblum
Date: 2009-01-11 00:57:08 -0700 (Sun, 11 Jan 2009)
New Revision: 10205

Modified:
   gnuradio/trunk/grc/src/platforms/gui/Param.py
   gnuradio/trunk/grc/src/platforms/python/FlowGraph.py
Log:
cache evaluated statements, do not parse huge vectors for display

Modified: gnuradio/trunk/grc/src/platforms/gui/Param.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Param.py       2009-01-09 03:43:19 UTC 
(rev 10204)
+++ gnuradio/trunk/grc/src/platforms/gui/Param.py       2009-01-11 07:57:08 UTC 
(rev 10205)
@@ -118,7 +118,8 @@
                        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)

Modified: gnuradio/trunk/grc/src/platforms/python/FlowGraph.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/python/FlowGraph.py        2009-01-09 
03:43:19 UTC (rev 10204)
+++ gnuradio/trunk/grc/src/platforms/python/FlowGraph.py        2009-01-11 
07:57:08 UTC (rev 10205)
@@ -40,6 +40,22 @@
 
 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 @@
                        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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]