summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Kamat <jaygkamat@gmail.com>2017-10-14 17:49:27 -0400
committerFlorian Bruhin <git@the-compiler.org>2017-10-31 07:06:36 +0100
commit0becdfa6b07168b0f030308f5f78af16cf1fd475 (patch)
tree2f0c1873d992821039819aff10f26d9b15c5f14d
parentb69b5c81fccf531857733d686620f34f5a8d94b5 (diff)
downloadqutebrowser-0becdfa6b07168b0f030308f5f78af16cf1fd475.tar.gz
qutebrowser-0becdfa6b07168b0f030308f5f78af16cf1fd475.zip
Add caching for tab sizes
(cherry picked from commit 08b562ea0c52e6dfa496055371ed668777adc418)
-rw-r--r--qutebrowser/mainwindow/tabwidget.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py
index c5566f877..55bd76f79 100644
--- a/qutebrowser/mainwindow/tabwidget.py
+++ b/qutebrowser/mainwindow/tabwidget.py
@@ -424,7 +424,7 @@ class TabBar(QTabBar):
return
super().mousePressEvent(e)
- def minimumTabSizeHint(self, index, ellipsis: bool = True):
+ def minimumTabSizeHint(self, index, ellipsis: bool = True) -> QSize:
"""Set the minimum tab size to indicator/icon/... text.
Args:
@@ -434,11 +434,18 @@ class TabBar(QTabBar):
Return:
A QSize of the smallest tab size we can make.
"""
- text = '\u2026' if ellipsis else self.tabText(index)
+ return self.__minimumTabSizeHintHelper(self.tabText(index),
+ self.tabIcon(index), ellipsis)
+
+ @functools.lru_cache(maxsize=100)
+ def __minimumTabSizeHintHelper(self, tab_text: str,
+ icon,
+ ellipsis: bool) -> QSize:
+ """Helper function to cache tab results."""
+ text = '\u2026' if ellipsis else tab_text
# Don't ever shorten if text is shorter than the ellipsis
text_width = min(self.fontMetrics().width(text),
- self.fontMetrics().width(self.tabText(index)))
- icon = self.tabIcon(index)
+ self.fontMetrics().width(tab_text))
padding = config.val.tabs.padding
indicator_padding = config.val.tabs.indicator_padding
padding_h = padding.left + padding.right