From c4e748d9747bea9b0a011dd4f05bef7d70d70e7f Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 13 May 2013 13:28:04 +0400 Subject: [PATCH] memory: intern frequent type text in cls references --- .../src/com/intellij/psi/impl/cache/TypeInfo.java | 10 ++++++---- .../impl/compiled/ClsJavaCodeReferenceElementImpl.java | 7 +++++-- .../intellij/psi/impl/compiled/ClsTypeElementImpl.java | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/cache/TypeInfo.java b/java/java-psi-impl/src/com/intellij/psi/impl/cache/TypeInfo.java index d9d3b0612133..2adc6f1a9947 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/cache/TypeInfo.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/cache/TypeInfo.java @@ -65,8 +65,10 @@ public class TypeInfo { "null", "short", "void", - CommonClassNames.JAVA_LANG_OBJECT_SHORT, CommonClassNames.JAVA_LANG_OBJECT, - CommonClassNames.JAVA_LANG_STRING_SHORT, CommonClassNames.JAVA_LANG_STRING + CommonClassNames.JAVA_LANG_OBJECT_SHORT, + CommonClassNames.JAVA_LANG_OBJECT, + CommonClassNames.JAVA_LANG_STRING_SHORT, + CommonClassNames.JAVA_LANG_STRING }; ourFrequentTypeIndex = new TObjectIntHashMap(); @@ -273,11 +275,11 @@ public class TypeInfo { buf.append("..."); } - return buf.toString(); + return internFrequentType(buf.toString()); } @NotNull - private static String internFrequentType(@NotNull String type) { + public static String internFrequentType(@NotNull String type) { int frequentIndex = ourFrequentTypeIndex.get(type); return frequentIndex == 0 ? type : ourIndexFrequentType[frequentIndex]; } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java index c69391dab891..7c2e8e0e5068 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsJavaCodeReferenceElementImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.intellij.psi.impl.PsiSubstitutorImpl; +import com.intellij.psi.impl.cache.TypeInfo; import com.intellij.psi.impl.source.resolve.ResolveCache; import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.impl.source.tree.TreeElement; @@ -45,8 +46,10 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P public ClsJavaCodeReferenceElementImpl(PsiElement parent, String canonicalText) { myParent = parent; - myCanonicalText = canonicalText; - myQualifiedName = PsiNameHelper.getQualifiedClassName(myCanonicalText, false); + String canonical = TypeInfo.internFrequentType(canonicalText); + myCanonicalText = canonical; + String qName = TypeInfo.internFrequentType(PsiNameHelper.getQualifiedClassName(myCanonicalText, false)); + myQualifiedName = qName.equals(canonical) ? canonical : qName; String[] classParameters = PsiNameHelper.getClassParametersText(canonicalText); myRefParameterList = classParameters.length == 0 ? null : new ClsReferenceParameterListImpl(this, classParameters); diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java index f8b821bfd1e5..62148d7be3fb 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/compiled/ClsTypeElementImpl.java @@ -17,6 +17,7 @@ package com.intellij.psi.impl.compiled; import com.intellij.psi.*; import com.intellij.psi.impl.PsiImplUtil; +import com.intellij.psi.impl.cache.TypeInfo; import com.intellij.psi.impl.source.PsiClassReferenceType; import com.intellij.psi.impl.source.tree.JavaElementType; import com.intellij.psi.impl.source.tree.TreeElement; @@ -40,7 +41,7 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement public ClsTypeElementImpl(@NotNull PsiElement parent, @NotNull String typeText, char variance) { myParent = parent; - myTypeText = typeText; + myTypeText = TypeInfo.internFrequentType(typeText); myVariance = variance; }