PY-23150: Numpy custom members take significant time to resolve since they are looking up DTYPE each time for each member. Instead resolve it once.

(cherry picked from commit 5702120)
This commit is contained in:
fitermay
2017-04-17 19:22:54 +03:00
committed by Mikhail Golubev
parent 2514a8b515
commit 2072c80a34
@@ -18,6 +18,7 @@ package com.jetbrains.numpy.codeInsight;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.QualifiedName;
import com.jetbrains.python.codeInsight.PyCustomMember;
import com.jetbrains.python.codeInsight.PyPsiPath;
import com.jetbrains.python.psi.PyFile;
import com.jetbrains.python.psi.PyUtil;
import com.jetbrains.python.psi.resolve.PyQualifiedNameResolveContext;
@@ -54,15 +55,18 @@ public class NumpyModuleMembersProvider extends PyModuleMembersProvider {
@Override
protected Collection<PyCustomMember> getMembersByQName(PyFile module, String qName) {
if ("numpy".equals(qName)) {
final List<PyCustomMember> members = new ArrayList<>();
for (String type : NUMERIC_TYPES) {
members.add(new PyCustomMember(type, DTYPE, false));
PsiElement clazz = new PyPsiPath.ToClassQName(DTYPE).resolve(module);
if (clazz != null) {
final List<PyCustomMember> members = new ArrayList<>();
for (String type : NUMERIC_TYPES) {
members.add(new PyCustomMember(type, clazz, DTYPE));
}
for (String type : PYTHON_TYPES) {
members.add(new PyCustomMember(type, clazz, DTYPE));
}
addTestingModule(module, members);
return members;
}
for (String type : PYTHON_TYPES) {
members.add(new PyCustomMember(type, DTYPE, false));
}
addTestingModule(module, members);
return members;
}
return Collections.emptyList();
}