Use config cache to cache static hotspots
This commit is contained in:
parent
067d76616b
commit
0335fc31c1
@ -34,6 +34,7 @@ from qutebrowser.keyinput import keyutils
|
||||
val = None
|
||||
instance = None
|
||||
key_instance = None
|
||||
configcache = None
|
||||
|
||||
# Keeping track of all change filters to validate them later.
|
||||
change_filters = []
|
||||
|
@ -20,9 +20,11 @@
|
||||
"""A 'high-performance' cache for the config system.
|
||||
|
||||
Useful for areas which call out to the config system very frequently, DO NOT
|
||||
modify the value returned, and DO NOT require per-url settings.
|
||||
modify the value returned, DO NOT require per-url settings, do not change
|
||||
frequently, and do not require partially 'expanded' config paths.
|
||||
|
||||
If any of these requirements are broken, you will get incorrect behavior.
|
||||
If any of these requirements are broken, you will get incorrect or slow
|
||||
behavior.
|
||||
"""
|
||||
|
||||
from qutebrowser.config import config
|
||||
@ -38,7 +40,10 @@ class ConfigCache():
|
||||
if attr in self.cache:
|
||||
self.cache[attr] = config.instance.get(attr)
|
||||
|
||||
def __getattr__(self, attr: str):
|
||||
def __setitem__(self, attr):
|
||||
raise Exception("ConfigCache cannot be used to set values.")
|
||||
|
||||
def __getitem__(self, attr: str):
|
||||
if attr not in self.cache:
|
||||
assert not config.instance.get_opt(attr).supports_pattern
|
||||
self.cache[attr] = config.instance.get(attr)
|
||||
|
@ -28,6 +28,7 @@ from qutebrowser.config import (config, configdata, configfiles, configtypes,
|
||||
configexc, configcommands)
|
||||
from qutebrowser.utils import (objreg, usertypes, log, standarddir, message,
|
||||
qtutils)
|
||||
from qutebrowser.config import configcache
|
||||
from qutebrowser.misc import msgbox, objects
|
||||
|
||||
|
||||
@ -44,6 +45,7 @@ def early_init(args):
|
||||
config.instance = config.Config(yaml_config=yaml_config)
|
||||
config.val = config.ConfigContainer(config.instance)
|
||||
config.key_instance = config.KeyConfig(config.instance)
|
||||
config.configcache = configcache.ConfigCache()
|
||||
yaml_config.setParent(config.instance)
|
||||
|
||||
for cf in config.change_filters:
|
||||
|
@ -719,9 +719,9 @@ class TabbedBrowser(QWidget):
|
||||
except TabDeletedError:
|
||||
# We can get signals for tabs we already deleted...
|
||||
return
|
||||
start = config.val.colors.tabs.indicator.start
|
||||
stop = config.val.colors.tabs.indicator.stop
|
||||
system = config.val.colors.tabs.indicator.system
|
||||
start = config.configcache['colors.tabs.indicator.start']
|
||||
stop = config.configcache['colors.tabs.indicator.stop']
|
||||
system = config.configcache['colors.tabs.indicator.system']
|
||||
color = utils.interpolate_color(start, stop, perc, system)
|
||||
self.widget.set_tab_indicator_color(idx, color)
|
||||
self.widget.update_tab_title(idx)
|
||||
|
@ -139,9 +139,9 @@ class TabWidget(QTabWidget):
|
||||
"""
|
||||
tab = self.widget(idx)
|
||||
if tab.data.pinned:
|
||||
fmt = config.val.tabs.title.format_pinned
|
||||
fmt = config.configcache['tabs.title.format_pinned']
|
||||
else:
|
||||
fmt = config.val.tabs.title.format
|
||||
fmt = config.configcache['tabs.title.format']
|
||||
|
||||
if (field is not None and
|
||||
(fmt is None or ('{' + field + '}') not in fmt)):
|
||||
@ -604,7 +604,7 @@ class TabBar(QTabBar):
|
||||
minimum_size = self.minimumTabSizeHint(index)
|
||||
height = minimum_size.height()
|
||||
if self.vertical:
|
||||
confwidth = str(config.val.tabs.width)
|
||||
confwidth = str(config.configcache['tabs.width'])
|
||||
if confwidth.endswith('%'):
|
||||
main_window = objreg.get('main-window', scope='window',
|
||||
window=self._win_id)
|
||||
@ -614,7 +614,7 @@ class TabBar(QTabBar):
|
||||
width = int(confwidth)
|
||||
size = QSize(max(minimum_size.width(), width), height)
|
||||
else:
|
||||
if config.val.tabs.pinned.shrink:
|
||||
if config.configcache['tabs.pinned.shrink']:
|
||||
pinned = self._tab_pinned(index)
|
||||
pinned_count, pinned_width = self._pinned_statistics()
|
||||
else:
|
||||
@ -652,15 +652,15 @@ class TabBar(QTabBar):
|
||||
tab = QStyleOptionTab()
|
||||
self.initStyleOption(tab, idx)
|
||||
|
||||
# pylint: disable=bad-config-option
|
||||
setting = config.val.colors.tabs
|
||||
# pylint: enable=bad-config-option
|
||||
setting = 'colors.tabs'
|
||||
if idx == selected:
|
||||
setting = setting.selected
|
||||
setting = setting.odd if (idx + 1) % 2 else setting.even
|
||||
setting += '.selected'
|
||||
setting += '.odd' if (idx + 1) % 2 else '.even'
|
||||
|
||||
tab.palette.setColor(QPalette.Window, setting.bg)
|
||||
tab.palette.setColor(QPalette.WindowText, setting.fg)
|
||||
tab.palette.setColor(QPalette.Window,
|
||||
config.configcache[setting + '.bg'])
|
||||
tab.palette.setColor(QPalette.WindowText,
|
||||
config.configcache[setting + '.fg'])
|
||||
|
||||
indicator_color = self.tab_indicator_color(idx)
|
||||
tab.palette.setColor(QPalette.Base, indicator_color)
|
||||
@ -805,7 +805,7 @@ class TabBarStyle(QCommonStyle):
|
||||
elif element == QStyle.CE_TabBarTabLabel:
|
||||
if not opt.icon.isNull() and layouts.icon.isValid():
|
||||
self._draw_icon(layouts, opt, p)
|
||||
alignment = (config.val.tabs.title.alignment |
|
||||
alignment = (config.configcache['tabs.title.alignment'] |
|
||||
Qt.AlignVCenter | Qt.TextHideMnemonic)
|
||||
self._style.drawItemText(p, layouts.text, alignment, opt.palette,
|
||||
opt.state & QStyle.State_Enabled,
|
||||
@ -878,8 +878,8 @@ class TabBarStyle(QCommonStyle):
|
||||
Return:
|
||||
A Layout object with two QRects.
|
||||
"""
|
||||
padding = config.val.tabs.padding
|
||||
indicator_padding = config.val.tabs.indicator.padding
|
||||
padding = config.configcache['tabs.padding']
|
||||
indicator_padding = config.configcache['tabs.indicator.padding']
|
||||
|
||||
text_rect = QRect(opt.rect)
|
||||
if not text_rect.isValid():
|
||||
@ -890,7 +890,7 @@ class TabBarStyle(QCommonStyle):
|
||||
text_rect.adjust(padding.left, padding.top, -padding.right,
|
||||
-padding.bottom)
|
||||
|
||||
indicator_width = config.val.tabs.indicator.width
|
||||
indicator_width = config.configcache['tabs.indicator.width']
|
||||
if indicator_width == 0:
|
||||
indicator_rect = QRect()
|
||||
else:
|
||||
@ -933,9 +933,9 @@ class TabBarStyle(QCommonStyle):
|
||||
icon_state = (QIcon.On if opt.state & QStyle.State_Selected
|
||||
else QIcon.Off)
|
||||
# reserve space for favicon when tab bar is vertical (issue #1968)
|
||||
position = config.val.tabs.position
|
||||
position = config.configcache['tabs.position']
|
||||
if (position in [QTabWidget.East, QTabWidget.West] and
|
||||
config.val.tabs.favicons.show != 'never'):
|
||||
config.configcache['tabs.favicons.show'] != 'never'):
|
||||
tab_icon_size = icon_size
|
||||
else:
|
||||
actual_size = opt.icon.actualSize(icon_size, icon_mode, icon_state)
|
||||
|
Loading…
Reference in New Issue
Block a user