[rhmessaging-commits] rhmessaging commits: r1045 - mgmt/cumin/python/wooly.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Sat Oct 13 14:49:14 EDT 2007


Author: justi9
Date: 2007-10-13 14:49:14 -0400 (Sat, 13 Oct 2007)
New Revision: 1045

Modified:
   mgmt/cumin/python/wooly/__init__.py
Log:
Makes widget and parameter lookups faster.



Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py	2007-10-13 17:59:35 UTC (rev 1044)
+++ mgmt/cumin/python/wooly/__init__.py	2007-10-13 18:49:14 UTC (rev 1045)
@@ -27,8 +27,6 @@
 
         app.add_widget(self)
 
-        self.strings = None
-
     def ancestors(self):
         if not self.cached_ancestors:
             if not self.parent:
@@ -331,9 +329,11 @@
         self.pages = dict()
         self.default_page = None
 
-        # Registration lists XXX get rid of?
         self.widgets = list()
+        self.widget_index = None
+
         self.parameters = list()
+        self.parameter_index = None
 
         self.finder = ResourceFinder()
         self.cached_css = None
@@ -362,24 +362,39 @@
         self.default_page = page
 
     def add_widget(self, widget):
+        if self.widget_index:
+            raise Exception()
+        
         self.widgets.append(widget)
 
     def get_widget(self, key):
-        # XXX not fast
-        for widget in self.widgets:
-            if widget.path() == key:
-                return widget
+        if not self.widget_index:
+            index = dict()
 
+            for widget in self.widgets:
+                index[widget.path()] = widget
+
+            self.widget_index = index
+
+        return self.widget_index.get(key)
+
     def add_parameter(self, param):
+        if self.parameter_index:
+            raise Exception()
+        
         self.parameters.append(param)
 
     def get_parameter(self, key):
-        # XXX not fast
-        for param in self.parameters:
-            # XXX I'm not sure the param.widget test is what I want
-            if param.widget and param.path() == key:
-                return param
+        if not self.parameter_index:
+            index = dict()
 
+            for param in self.parameters:
+                index[param.path()] = param
+
+            self.parameter_index = index
+
+        return self.parameter_index.get(key)
+
     def add_resource_dir(self, dir):
         self.finder.add_dir(dir)
 




More information about the rhmessaging-commits mailing list