From ee2dbbf5c6343de1a836d34d560dccbaf2dc70df Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 20 Mar 2008 20:19:33 +0300 Subject: [PATCH] Speed up python parsing a bit --- python/src/com/jetbrains/python/psi/PyElementType.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/src/com/jetbrains/python/psi/PyElementType.java b/python/src/com/jetbrains/python/psi/PyElementType.java index 1ae9a3347348..0caf5ea33b73 100644 --- a/python/src/com/jetbrains/python/psi/PyElementType.java +++ b/python/src/com/jetbrains/python/psi/PyElementType.java @@ -11,9 +11,12 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Constructor; + public class PyElementType extends IElementType { protected Class _psiElementClass; private static final Class[] PARAMETER_TYPES = new Class[]{ASTNode.class}; + private Constructor myConstructor; public PyElementType(@NotNull @NonNls String debugName) { super(debugName, PythonFileType.INSTANCE.getLanguage()); @@ -31,7 +34,11 @@ public class PyElementType extends IElementType { } try { - return _psiElementClass.getConstructor(PARAMETER_TYPES).newInstance(node); + if (myConstructor == null) { + myConstructor = _psiElementClass.getConstructor(PARAMETER_TYPES); + } + + return myConstructor.newInstance(node); } catch (Exception e) { throw new IllegalStateException("No necessary constructor for " + node.getElementType(), e);