Use an LRU cache for stylesheets
This commit is contained in:
parent
5176dac391
commit
6d2acc244c
@ -394,7 +394,7 @@ class Application(QApplication):
|
||||
status.prompt.prompter.ask_question, Qt.DirectConnection)
|
||||
|
||||
# config
|
||||
self.config.style_changed.connect(style.invalidate_caches)
|
||||
self.config.style_changed.connect(style.get_stylesheet.cache_clear)
|
||||
for obj in (tabs, completion, self.mainwindow, self.cmd_history,
|
||||
websettings, kp[utypes.KeyMode.normal], self.modeman,
|
||||
status, status.txt):
|
||||
|
@ -17,12 +17,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Utilities related to the look&feel of qutebrowser.
|
||||
|
||||
Module attributes:
|
||||
_colordict: The global cached ColorDict.
|
||||
_fontdict: The global cached FontDict.
|
||||
"""
|
||||
"""Utilities related to the look&feel of qutebrowser."""
|
||||
|
||||
import functools
|
||||
|
||||
@ -32,10 +27,7 @@ from qutebrowser.config import config
|
||||
from qutebrowser.utils import log, utils
|
||||
|
||||
|
||||
_colordict = None
|
||||
_fontdict = None
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=16)
|
||||
def get_stylesheet(template):
|
||||
"""Format a stylesheet based on a template.
|
||||
|
||||
@ -45,12 +37,9 @@ def get_stylesheet(template):
|
||||
Return:
|
||||
The formatted template as string.
|
||||
"""
|
||||
global _colordict, _fontdict
|
||||
if _colordict is None:
|
||||
_colordict = ColorDict(config.section('colors'))
|
||||
if _fontdict is None:
|
||||
_fontdict = FontDict(config.section('fonts'))
|
||||
return template.strip().format(color=_colordict, font=_fontdict,
|
||||
colordict = ColorDict(config.section('colors'))
|
||||
fontdict = FontDict(config.section('fonts'))
|
||||
return template.strip().format(color=colordict, font=fontdict,
|
||||
config=config.instance())
|
||||
|
||||
|
||||
@ -78,15 +67,6 @@ def _update_stylesheet(obj, _section, _option):
|
||||
obj.setStyleSheet(get_stylesheet(obj.STYLESHEET))
|
||||
|
||||
|
||||
def invalidate_caches(section, _option):
|
||||
"""Invalidate cached dicts."""
|
||||
global _colordict, _fontdict
|
||||
if section == 'colors':
|
||||
_colordict = None
|
||||
elif section == 'fonts':
|
||||
_fontdict = None
|
||||
|
||||
|
||||
class ColorDict(dict):
|
||||
|
||||
"""A dict aimed at Qt stylesheet colors."""
|
||||
|
@ -29,7 +29,7 @@ from PyQt5.QtCore import pyqtRemoveInputHook, QEvent, QCoreApplication
|
||||
|
||||
from qutebrowser.utils import log, utils
|
||||
from qutebrowser.commands import cmdutils
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.config import config, style
|
||||
|
||||
|
||||
@cmdutils.register(debug=True, name='debug-set-trace')
|
||||
@ -87,9 +87,11 @@ def debug_all_objects():
|
||||
|
||||
@cmdutils.register(debug=True)
|
||||
def debug_cache_stats():
|
||||
"""Print config LRU cache stats."""
|
||||
info = config.instance().get.cache_info()
|
||||
log.misc.debug(info)
|
||||
"""Print LRU cache stats."""
|
||||
config_info = config.instance().get.cache_info()
|
||||
style_info = style.get_stylesheet.cache_info()
|
||||
log.misc.debug('config: {}'.format(config_info))
|
||||
log.misc.debug('style: {}'.format(style_info))
|
||||
|
||||
|
||||
def log_events(klass):
|
||||
|
Loading…
Reference in New Issue
Block a user