Improve performance of startup and shutdown
We call 'update_tab_titles' a lot of times which calls 'setTabText' on every tab. 'setTabText' calls tabSizeHint and minTabSizeHint on every tab as well, meaning this is an n^2 operation repeated many times. First, this prevents setTabText from being called unless it's needed, removing most of the work done. Second, I remove tabs in reverse, to avoid recomputing the above for every tab on shutdown (which is at least n^3)
This commit is contained in:
parent
80ee43beca
commit
33d9d4fe90
@ -253,7 +253,10 @@ class TabbedBrowser(tabwidget.TabWidget):
|
||||
def shutdown(self):
|
||||
"""Try to shut down all tabs cleanly."""
|
||||
self.shutting_down = True
|
||||
for tab in self.widgets():
|
||||
# Reverse tabs so we don't have to recacluate tab titles over and over
|
||||
# Removing first causes [2..-1] to be recomputed
|
||||
# Removing the last causes nothing to be recomputed
|
||||
for tab in reversed(self.widgets()):
|
||||
self._remove_tab(tab)
|
||||
|
||||
def tab_close_prompt_if_pinned(
|
||||
|
@ -150,8 +150,9 @@ class TabWidget(QTabWidget):
|
||||
title = '' if fmt is None else fmt.format(**fields)
|
||||
tabbar = self.tabBar()
|
||||
|
||||
tabbar.setTabText(idx, title)
|
||||
tabbar.setTabToolTip(idx, title)
|
||||
if tabbar.tabText(idx) != title:
|
||||
tabbar.setTabText(idx, title)
|
||||
tabbar.setTabToolTip(idx, title)
|
||||
|
||||
def get_tab_fields(self, idx):
|
||||
"""Get the tab field data."""
|
||||
|
Loading…
Reference in New Issue
Block a user