OSDN Git Service

board window performance improvement
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Thu, 17 Aug 2006 00:42:54 +0000 (09:42 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Thu, 17 Aug 2006 00:42:54 +0000 (09:42 +0900)
src/Hage1/board_window.py

index 1da5a4c..6086e50 100644 (file)
@@ -165,6 +165,11 @@ class ThreadListModel(gtk.GenericTreeModel):
         self.sort_reverse = sort_reverse
         self.do_sort(self.sort_column_name, self.sort_reverse)
 
+    def build_order_dict(self):
+        # key: thread id, value: index in self.list
+        self.order_dict = dict(
+            [(item["id"], index) for index, item in enumerate(self.list)])
     def compare(self, v1, v2, reverse):
         if not reverse:
             if v1 == 0 and v2 == 0:
@@ -184,11 +189,10 @@ class ThreadListModel(gtk.GenericTreeModel):
         else:
             h = lambda x, y: self.compare(x, y, reverse)
             self.list.sort(h, lambda dic: dic[column_name], reverse)
+        self.build_order_dict()
 
     def sort(self, column_name):
-        oldorder_dic = {}
-        for index, item in enumerate(self.list):
-            oldorder_dic[item["id"]] = index
+        old_order_dict = self.order_dict
 
         if column_name == self.sort_column_name:
             # sort reverse
@@ -199,9 +203,7 @@ class ThreadListModel(gtk.GenericTreeModel):
 
         self.do_sort(self.sort_column_name, self.sort_reverse)
 
-        neworder = []
-        for item in self.list:
-            neworder.append(oldorder_dic[item["id"]])
+        neworder = [old_order_dict[item["id"]] for item in self.list]
         self.rows_reordered(None, None, neworder)
 
     def on_get_flags(self):
@@ -217,14 +219,14 @@ class ThreadListModel(gtk.GenericTreeModel):
         return self.list[path[0]]
 
     def on_get_path(self, rowref):
-        return self.list.index(rowref)
+        return self.order_dict[rowref["id"]]
 
     def on_get_value(self, rowref, column):
         return rowref[self.column_names[column]]
 
     def on_iter_next(self, rowref):
         try:
-            i = self.list.index(rowref)+1
+            i = self.order_dict[rowref["id"]] + 1
             return self.list[i]
         except IndexError:
             return None