autotrigger: solve performance issues

This commit is contained in:
Stanislav Seletskiy 2015-10-15 14:55:14 +06:00
parent 76ebfec3cf
commit 6ad7472aac
3 changed files with 9 additions and 4 deletions

View File

@ -16,7 +16,7 @@ class SnippetSource(object):
self._snippets = defaultdict(SnippetDictionary) self._snippets = defaultdict(SnippetDictionary)
self._extends = defaultdict(set) self._extends = defaultdict(set)
def ensure(self, filetypes): def ensure(self, filetypes, cached):
"""Update/reload the snippets in the source when needed. """Update/reload the snippets in the source when needed.
It makes sure that the snippets are not outdated. It makes sure that the snippets are not outdated.

View File

@ -36,12 +36,18 @@ class SnippetFileSource(SnippetSource):
SnippetSource.__init__(self) SnippetSource.__init__(self)
self._files_for_ft = defaultdict(set) self._files_for_ft = defaultdict(set)
self._file_hashes = defaultdict(lambda: None) 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): for ft in self.get_deep_extends(filetypes):
if self._needs_update(ft): if self._needs_update(ft):
self._load_snippets_for(ft) self._load_snippets_for(ft)
self._ensure_cached = True
def _get_all_snippet_files_for(self, ft): def _get_all_snippet_files_for(self, ft):
"""Returns a set of all files that define snippets for 'ft'.""" """Returns a set of all files that define snippets for 'ft'."""
raise NotImplementedError() raise NotImplementedError()

View File

@ -554,8 +554,7 @@ class SnippetManager(object):
clear_priority = None clear_priority = None
cleared = {} cleared = {}
for _, source in self._snippet_sources: for _, source in self._snippet_sources:
if not autotrigger_only or not source.loaded(filetypes): source.ensure(filetypes, cached=autotrigger_only)
source.ensure(filetypes)
# Collect cleared information from sources. # Collect cleared information from sources.
for _, source in self._snippet_sources: for _, source in self._snippet_sources: