Commits

Yuya Nishihara  committed 6dbf630

manifestmodel: keep icon cache by model to avoid regeneration on filter change

  • Participants
  • Parent commits 76752e0

Comments (0)

Files changed (1)

File tortoisehg/hgqt/manifestmodel.py

         QAbstractItemModel.__init__(self, parent)
 
         self._fileiconprovider = QFileIconProvider()
+        self._iconcache = {}  # (path, status, subkind): icon
         self._repo = repo
         self._rev = rev
 
         if not index.isValid():
             return QIcon()
         e = index.internalPointer()
-        if e.icon:
-            return e.icon
-        ic = self._makeFileIcon(e)
-        e.icon = ic
-        return ic
+        k = (e.path, e.status, e.subkind)
+        try:
+            return self._iconcache[k]
+        except KeyError:
+            self._iconcache[k] = ic = self._makeFileIcon(e)
+            return ic
 
     def _makeFileIcon(self, e):
         if e.status == 'S' and e.subkind in _subrepoType2IcoMap:
 class _Entry(object):
     """Each file or directory"""
 
-    __slots__ = ('_name', '_parent', 'status', 'ctx', 'subkind', 'icon',
+    __slots__ = ('_name', '_parent', 'status', 'ctx', 'subkind',
                  '_child', '_nameindex')
 
     def __init__(self, name='', parent=None):
         self.status = None
         self.ctx = None
         self.subkind = None
-        self.icon = None
         self._child = {}
         self._nameindex = []