1
0
forked from VimPlug/jedi

the last commit featured an incomplete caching for compiled objects. The current one should improve this.

This commit is contained in:
Dave Halter
2014-04-13 21:55:29 +02:00
parent 4bc55be103
commit 3fced34544
2 changed files with 19 additions and 7 deletions

View File

@@ -83,9 +83,11 @@ class CompiledObject(Base):
return self
def get_defined_names(self):
names = []
cls = self._cls()
for name in dir(cls.obj):
yield CompiledName(cls, name)
names.append(CompiledName(cls, name))
return names
def instance_names(self):
return self.get_defined_names()
@@ -337,17 +339,26 @@ def _create_from_name(module, parent, name):
return CompiledObject(obj, parent)
def compiled_objects_cache(func):
def wrapper(evaluator, obj, parent=builtin, module=None):
# Do a very cheap form of caching here.
key = id(obj), id(parent), id(module)
try:
return evaluator.compiled_cache[key][0]
except KeyError:
result = func(evaluator, obj, parent, module)
# Need to cache all of them, otherwise the id could be overwritten.
evaluator.compiled_cache[key] = result, obj, parent, module
return result
return wrapper
@compiled_objects_cache
def create(evaluator, obj, parent=builtin, module=None):
"""
A very weird interface class to this module. The more options provided the
more acurate loading compiled objects is.
"""
# Do a very cheap form of caching here.
key = id(obj), id(parent), id(module)
try:
return evaluator.compiled_cache[key]
except KeyError:
pass
if not inspect.ismodule(obj):
faked = fake.get_faked(module and module.obj, obj)

View File

@@ -86,6 +86,7 @@ class GeneratorMethod(object):
return self._generator.iter_content()
def __getattr__(self, name):
print(self, name)
return getattr(self._builtin_func, name)