commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11246 - gnuradio/branches/developers/jblum/grc/grc/py


From: jblum
Subject: [Commit-gnuradio] r11246 - gnuradio/branches/developers/jblum/grc/grc/python
Date: Fri, 19 Jun 2009 23:55:00 -0600 (MDT)

Author: jblum
Date: 2009-06-19 23:54:59 -0600 (Fri, 19 Jun 2009)
New Revision: 11246

Modified:
   gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py
Log:
speed up the eval cache -> store the namespace hash

Modified: gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py      
2009-06-20 02:34:03 UTC (rev 11245)
+++ gnuradio/branches/developers/jblum/grc/grc/python/FlowGraph.py      
2009-06-20 05:54:59 UTC (rev 11246)
@@ -40,14 +40,15 @@
 class FlowGraph(_FlowGraph):
 
        _eval_cache = dict()
-       def _eval(self, code, namespace):
+       def _eval(self, code, namespace, namespace_hash):
                """
                Evaluate the code with the given namespace.
                @param code a string with python code
                @param namespace a dict representing the namespace
+               @param namespace_hash a unique hash for the namespace
                @return the resultant object
                """
-               my_hash = hash(code + str(namespace))
+               my_hash = hash(code) ^ namespace_hash
                #cache if does not exist
                if not self._eval_cache.has_key(my_hash):
                        self._eval_cache[my_hash] = eval(code, namespace, 
namespace)
@@ -147,18 +148,19 @@
                        np = dict()
                        for parameter in self.get_parameters():
                                try:
-                                       e = 
self._eval(_get_value_expr(parameter), n)
+                                       e = eval(_get_value_expr(parameter), n, 
n)
                                        np[parameter.get_id()] = e
                                except: pass
                        n.update(np) #merge param namespace
                        #load variables
                        for variable in self.get_variables():
                                try:
-                                       e = 
self._eval(_get_value_expr(variable), n)
+                                       e = eval(_get_value_expr(variable), n, 
n)
                                        n[variable.get_id()] = e
                                except: pass
                        #make namespace public
                        self.n = n
+                       self.n_hash = hash(str(n))
                #evaluate
-               e = self._eval(expr, self.n)
+               e = self._eval(expr, self.n, self.n_hash)
                return e





reply via email to

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