From 6ad7472aac72f549924107e34da60767a0fdc9a0 Mon Sep 17 00:00:00 2001 From: Stanislav Seletskiy Date: Thu, 15 Oct 2015 14:55:14 +0600 Subject: [PATCH] autotrigger: solve performance issues --- pythonx/UltiSnips/snippet/source/_base.py | 2 +- pythonx/UltiSnips/snippet/source/file/_base.py | 8 +++++++- pythonx/UltiSnips/snippet_manager.py | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pythonx/UltiSnips/snippet/source/_base.py b/pythonx/UltiSnips/snippet/source/_base.py index c4141eb..aa38af3 100644 --- a/pythonx/UltiSnips/snippet/source/_base.py +++ b/pythonx/UltiSnips/snippet/source/_base.py @@ -16,7 +16,7 @@ class SnippetSource(object): self._snippets = defaultdict(SnippetDictionary) self._extends = defaultdict(set) - def ensure(self, filetypes): + def ensure(self, filetypes, cached): """Update/reload the snippets in the source when needed. It makes sure that the snippets are not outdated. diff --git a/pythonx/UltiSnips/snippet/source/file/_base.py b/pythonx/UltiSnips/snippet/source/file/_base.py index 6e639a0..daa3f1d 100644 --- a/pythonx/UltiSnips/snippet/source/file/_base.py +++ b/pythonx/UltiSnips/snippet/source/file/_base.py @@ -36,12 +36,18 @@ class SnippetFileSource(SnippetSource): SnippetSource.__init__(self) self._files_for_ft = defaultdict(set) self._file_hashes = defaultdict(lambda: None) + self._ensure_cached = False + + def ensure(self, filetypes, cached): + if cached and self._ensure_cached: + return - def ensure(self, filetypes): for ft in self.get_deep_extends(filetypes): if self._needs_update(ft): self._load_snippets_for(ft) + self._ensure_cached = True + def _get_all_snippet_files_for(self, ft): """Returns a set of all files that define snippets for 'ft'.""" raise NotImplementedError() diff --git a/pythonx/UltiSnips/snippet_manager.py b/pythonx/UltiSnips/snippet_manager.py index e54fd80..3cb5e60 100644 --- a/pythonx/UltiSnips/snippet_manager.py +++ b/pythonx/UltiSnips/snippet_manager.py @@ -554,8 +554,7 @@ class SnippetManager(object): clear_priority = None cleared = {} for _, source in self._snippet_sources: - if not autotrigger_only or not source.loaded(filetypes): - source.ensure(filetypes) + source.ensure(filetypes, cached=autotrigger_only) # Collect cleared information from sources. for _, source in self._snippet_sources: