1
0
forked from VimPlug/jedi

merged module_cache into parser_cache

This commit is contained in:
David Halter
2013-01-11 23:19:22 +01:00
parent 21ae8e4266
commit 2efb93273a
5 changed files with 19 additions and 23 deletions

View File

@@ -376,7 +376,7 @@ class Script(object):
return None, 0 return None, 0
try: try:
parser = cache.module_cache[self.source_path].parser parser = cache.parser_cache[self.source_path].parser
except KeyError: except KeyError:
return None, 0 return None, 0
part_parser = self._module.get_part_parser() part_parser = self._module.get_part_parser()

View File

@@ -16,11 +16,9 @@ star_import_cache = {}
# for fast_parser, should not be deleted # for fast_parser, should not be deleted
parser_cache = {} parser_cache = {}
# should also not be deleted
module_cache = {}
class ModuleCacheItem(object): class ParserCacheItem(object):
def __init__(self, parser, change_time=None): def __init__(self, parser, change_time=None):
self.parser = parser self.parser = parser
if change_time is None: if change_time is None:
@@ -46,7 +44,6 @@ def clear_caches(delete_all=False):
time_caches = [] time_caches = []
star_import_cache.clear() star_import_cache.clear()
parser_cache.clear() parser_cache.clear()
module_cache.clear()
else: else:
# normally just kill the expired entries, not all # normally just kill the expired entries, not all
for tc in time_caches: for tc in time_caches:
@@ -170,14 +167,14 @@ def load_module(path, name):
tim = os.path.getmtime(path) if path else None tim = os.path.getmtime(path) if path else None
try: try:
module_cache_item = module_cache[path or name] parser_cache_item = parser_cache[path or name]
if not path or tim <= module_cache_item.change_time: if not path or tim <= parser_cache_item.change_time:
return module_cache_item.parser return parser_cache_item.parser
else: else:
# In case there is already a module cached and this module # In case there is already a module cached and this module
# has to be reparsed, we also need to invalidate the import # has to be reparsed, we also need to invalidate the import
# caches. # caches.
invalidate_star_import_cache(module_cache_item.parser.module) invalidate_star_import_cache(parser_cache_item.parser.module)
except KeyError: except KeyError:
if settings.use_filesystem_cache: if settings.use_filesystem_cache:
return ModulePickling.load_module(path or name, tim) return ModulePickling.load_module(path or name, tim)
@@ -188,8 +185,8 @@ def save_module(path, name, parser, pickling=True):
return return
p_time = None if not path else os.path.getmtime(path) p_time = None if not path else os.path.getmtime(path)
item = ModuleCacheItem(parser, p_time) item = ParserCacheItem(parser, p_time)
module_cache[path or name] = item parser_cache[path or name] = item
if settings.use_filesystem_cache and pickling: if settings.use_filesystem_cache and pickling:
ModulePickling.save_module(path or name, item) ModulePickling.save_module(path or name, item)
@@ -210,15 +207,13 @@ class _ModulePickling(object):
return None return None
with open(self._get_hashed_path(path)) as f: with open(self._get_hashed_path(path)) as f:
module_cache_item = pickle.load(f) parser_cache_item = pickle.load(f)
parser = module_cache_item.parser
debug.dbg('pickle loaded', path) debug.dbg('pickle loaded', path)
parser_cache[path] = parser parser_cache[path] = parser_cache_item
module_cache[path] = module_cache_item return parser_cache_item.parser
return parser
def save_module(self, path, module_cache_item): def save_module(self, path, parser_cache_item):
try: try:
files = self._index[self.py_version] files = self._index[self.py_version]
except KeyError: except KeyError:
@@ -226,8 +221,8 @@ class _ModulePickling(object):
self._index[self.py_version] = files self._index[self.py_version] = files
with open(self._get_hashed_path(path), 'w') as f: with open(self._get_hashed_path(path), 'w') as f:
pickle.dump(module_cache_item, f, pickle.HIGHEST_PROTOCOL) pickle.dump(parser_cache_item, f, pickle.HIGHEST_PROTOCOL)
files[path] = module_cache_item.change_time files[path] = parser_cache_item.change_time
self._flush_index() self._flush_index()

View File

@@ -32,7 +32,7 @@ def get_directory_modules_for_name(mods, name):
""" """
def check_python_file(path): def check_python_file(path):
try: try:
return cache.module_cache[path].parser.module return cache.parser_cache[path].parser.module
except KeyError: except KeyError:
try: try:
return check_fs(path) return check_fs(path)

View File

@@ -140,12 +140,13 @@ class CachedFastParser(type):
if not settings.fast_parser: if not settings.fast_parser:
return parsing.PyFuzzyParser(source, module_path, user_position) return parsing.PyFuzzyParser(source, module_path, user_position)
p = cache.parser_cache.get(module_path, None) pi = cache.parser_cache.get(module_path, None)
if p is None or isinstance(p, parsing.PyFuzzyParser): if pi is None or isinstance(pi.parser, parsing.PyFuzzyParser):
p = super(CachedFastParser, self).__call__(source, module_path, p = super(CachedFastParser, self).__call__(source, module_path,
user_position) user_position)
cache.parser_cache[module_path] = p cache.parser_cache[module_path] = p
else: else:
p = pi.parser # pi is a `cache.ParserCacheItem`
p.update(source, user_position) p.update(source, user_position)
return p return p

View File

@@ -64,7 +64,7 @@ class ModuleWithCursor(Module):
""" get the parser lazy """ """ get the parser lazy """
if not self._parser: if not self._parser:
try: try:
parser = cache.module_cache[self.path].parser parser = cache.parser_cache[self.path].parser
cache.invalidate_star_import_cache(parser.module) cache.invalidate_star_import_cache(parser.module)
except KeyError: except KeyError:
pass pass