From 052fa8e27784b201fe3dbd79960514e2226715da Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 12 Sep 2014 17:38:40 +0200 Subject: [PATCH] Don't emit config changed signals during init. When we're initializing anyways nobody got a config value yet, so emitting the signals just will mean code gets executed twice. This reduces the startup time by about 1-2 seconds. --- qutebrowser/config/config.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/config.py b/qutebrowser/config/config.py index 33b26787f..514b766dd 100644 --- a/qutebrowser/config/config.py +++ b/qutebrowser/config/config.py @@ -94,6 +94,7 @@ class ConfigManager(QObject): _configfile: The config file path. _interpolation: An configparser.Interpolation object _proxies: configparser.SectionProxy objects for sections. + _initialized: Whether the ConfigManager is fully initialized yet. Signals: changed: Gets emitted when the config has changed. @@ -110,6 +111,7 @@ class ConfigManager(QObject): def __init__(self, configdir, fname, parent=None): super().__init__(parent) + self._initialized = False self.sections = configdata.DATA self._configparser = iniparsers.ReadConfigParser(configdir, fname) self._configfile = os.path.join(configdir, fname) @@ -126,6 +128,7 @@ class ConfigManager(QObject): for sectname in self.sections.keys(): self._proxies[sectname] = SectionProxy(self, sectname) self._from_cp(self._configparser) + self._initialized=True def __getitem__(self, key): """Get a section from the config.""" @@ -339,6 +342,9 @@ class ConfigManager(QObject): Return: The value of the option. """ + if not self._initialized: + raise Exception("get got called before initialisation was " + "complete!") try: sect = self.sections[sectname] except KeyError: @@ -434,7 +440,8 @@ class ConfigManager(QObject): except KeyError: raise NoOptionError(optname, sectname) else: - self._after_set(sectname, optname) + if self._initialized: + self._after_set(sectname, optname) @cmdutils.register(instance='config') def save(self):