mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java stubs: save memory by using String directly instead of StringRef
This commit is contained in:
@@ -81,22 +81,18 @@ public class TypeInfo {
|
||||
private static final int HAS_ARRAY_COUNT = 0x40;
|
||||
private static final int HAS_ELLIPSIS = 0x80;
|
||||
|
||||
private static final TypeInfo NULL = new TypeInfo((StringRef)null, (byte)0, false, PsiAnnotationStub.EMPTY_ARRAY);
|
||||
private static final TypeInfo NULL = new TypeInfo(null, (byte)0, false, PsiAnnotationStub.EMPTY_ARRAY);
|
||||
|
||||
public final StringRef text;
|
||||
public final String text;
|
||||
public final byte arrayCount;
|
||||
public final boolean isEllipsis;
|
||||
|
||||
private final PsiAnnotationStub[] myAnnotationStubs;
|
||||
|
||||
public TypeInfo(String text, byte arrayCount, boolean ellipsis, @NotNull PsiAnnotationStub[] annotationStubs) {
|
||||
this(StringRef.fromString(text == null ? null : internFrequentType(text)), arrayCount, ellipsis, annotationStubs);
|
||||
}
|
||||
|
||||
private TypeInfo(StringRef text, byte arrayCount, boolean isEllipsis, @NotNull PsiAnnotationStub[] annotationStubs) {
|
||||
this.text = text;
|
||||
this.text = text == null ? null : internFrequentType(text);
|
||||
this.arrayCount = arrayCount;
|
||||
this.isEllipsis = isEllipsis;
|
||||
this.isEllipsis = ellipsis;
|
||||
myAnnotationStubs = annotationStubs;
|
||||
}
|
||||
|
||||
@@ -123,7 +119,7 @@ public class TypeInfo {
|
||||
@NotNull
|
||||
public String getShortTypeText() {
|
||||
if (text == null) return "";
|
||||
String name = PsiNameHelper.getShortClassName(text.getString());
|
||||
String name = PsiNameHelper.getShortClassName(text);
|
||||
if (arrayCount > 0) {
|
||||
name += StringUtil.repeat("[]", arrayCount);
|
||||
}
|
||||
@@ -227,7 +223,7 @@ public class TypeInfo {
|
||||
byte arrayCount = isSet(flags, HAS_ARRAY_COUNT) ? record.readByte() : 0;
|
||||
boolean hasEllipsis = isSet(flags, HAS_ELLIPSIS);
|
||||
|
||||
StringRef text = frequentIndex == 0 ? record.readName() : StringRef.fromString(ourIndexFrequentType[frequentIndex]);
|
||||
String text = frequentIndex == 0 ? StringRef.toString(record.readName()) : ourIndexFrequentType[frequentIndex];
|
||||
|
||||
return new TypeInfo(text, arrayCount, hasEllipsis, PsiAnnotationStub.EMPTY_ARRAY);
|
||||
}
|
||||
@@ -238,7 +234,7 @@ public class TypeInfo {
|
||||
return;
|
||||
}
|
||||
|
||||
String text = typeInfo.text.getString();
|
||||
String text = typeInfo.text;
|
||||
byte arrayCount = typeInfo.arrayCount;
|
||||
int frequentIndex = ourFrequentTypeIndex.get(text);
|
||||
int flags = (typeInfo.isEllipsis ? HAS_ELLIPSIS : 0) | (arrayCount != 0 ? HAS_ARRAY_COUNT : 0) | frequentIndex;
|
||||
@@ -259,7 +255,7 @@ public class TypeInfo {
|
||||
return null;
|
||||
}
|
||||
if (typeInfo.arrayCount == 0 && typeInfo.myAnnotationStubs.length == 0) {
|
||||
return typeInfo.text.getString();
|
||||
return typeInfo.text;
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
@@ -268,7 +264,7 @@ public class TypeInfo {
|
||||
buf.append(stub.getText()).append(' ');
|
||||
}
|
||||
|
||||
buf.append(typeInfo.text.getString());
|
||||
buf.append(typeInfo.text);
|
||||
|
||||
int arrayCount = typeInfo.isEllipsis ? typeInfo.arrayCount - 1 : typeInfo.arrayCount;
|
||||
for (int i = 0; i < arrayCount; i++) {
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.intellij.psi.stubs.PsiFileStub;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.cls.ClsFormatException;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.org.objectweb.asm.*;
|
||||
@@ -344,7 +343,7 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
|
||||
|
||||
byte flags = PsiFieldStubImpl.packFlags((access & Opcodes.ACC_ENUM) != 0, (access & Opcodes.ACC_DEPRECATED) != 0, false, false);
|
||||
TypeInfo type = fieldType(desc, signature);
|
||||
String initializer = constToString(value, type.text.getString(), false);
|
||||
String initializer = constToString(value, type.text, false);
|
||||
PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, type, initializer, flags);
|
||||
PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access));
|
||||
return new AnnotationCollectingVisitor(modList);
|
||||
@@ -412,9 +411,8 @@ public class StubBuildingVisitor<T> extends ClassVisitor {
|
||||
List<String> args = new ArrayList<String>();
|
||||
List<String> throwables = exceptions != null ? new ArrayList<String>() : null;
|
||||
|
||||
StringRef stringRef = StringRef.fromString(canonicalMethodName);
|
||||
int modifiersMask = packMethodFlags(access, myResult.isInterface());
|
||||
PsiMethodStubImpl stub = new PsiMethodStubImpl(myResult, stringRef, flags, signature, args, throwables, desc, modifiersMask);
|
||||
PsiMethodStubImpl stub = new PsiMethodStubImpl(myResult, canonicalMethodName, flags, signature, args, throwables, desc, modifiersMask);
|
||||
|
||||
PsiModifierListStub modList = (PsiModifierListStub)stub.findChildStubByType(JavaStubElementTypes.MODIFIER_LIST);
|
||||
assert modList != null : stub;
|
||||
|
||||
@@ -119,7 +119,7 @@ public abstract class JavaMethodElementType extends JavaStubElementType<PsiMetho
|
||||
boolean isAnno = (node.getTokenType() == JavaElementType.ANNOTATION_METHOD);
|
||||
byte flags = PsiMethodStubImpl.packFlags(isConstructor, isAnno, isVarArgs, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
|
||||
|
||||
return new PsiMethodStubImpl(parentStub, StringRef.fromString(name), typeInfo, flags, StringRef.fromString(defValueText));
|
||||
return new PsiMethodStubImpl(parentStub, name, typeInfo, flags, defValueText);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,7 +139,7 @@ public abstract class JavaMethodElementType extends JavaStubElementType<PsiMetho
|
||||
final TypeInfo type = TypeInfo.readTYPE(dataStream);
|
||||
byte flags = dataStream.readByte();
|
||||
final StringRef defaultMethodValue = PsiMethodStubImpl.isAnnotationMethod(flags) ? dataStream.readName() : null;
|
||||
return new PsiMethodStubImpl(parentStub, name, type, flags, defaultMethodValue);
|
||||
return new PsiMethodStubImpl(parentStub, StringRef.toString(name), type, flags, StringRef.toString(defaultMethodValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.intellij.psi.stubs.StubBase;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.util.BitUtil;
|
||||
import com.intellij.util.cls.ClsFormatException;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -39,8 +38,8 @@ import java.util.List;
|
||||
public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodStub {
|
||||
private final TypeInfo myReturnType;
|
||||
private final byte myFlags;
|
||||
private final StringRef myName;
|
||||
private StringRef myDefaultValueText;
|
||||
private final String myName;
|
||||
private String myDefaultValueText;
|
||||
|
||||
private static final int CONSTRUCTOR = 0x01;
|
||||
private static final int VARARGS = 0x02;
|
||||
@@ -51,7 +50,7 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
|
||||
private static final int HAS_DOC_COMMENT = 0x40;
|
||||
|
||||
public PsiMethodStubImpl(StubElement parent,
|
||||
StringRef name,
|
||||
String name,
|
||||
byte flags,
|
||||
String signature,
|
||||
@NotNull List<String> args,
|
||||
@@ -81,7 +80,7 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
|
||||
myFlags = (byte)(flags | (parsedViaGenericSignature ? PARSED_VIA_GENERIC_SIGNATURE : 0));
|
||||
}
|
||||
|
||||
public PsiMethodStubImpl(StubElement parent, StringRef name, @NotNull TypeInfo returnType, byte flags, StringRef defaultValueText) {
|
||||
public PsiMethodStubImpl(StubElement parent, String name, @NotNull TypeInfo returnType, byte flags, @Nullable String defaultValueText) {
|
||||
super(parent, isAnnotationMethod(flags) ? JavaStubElementTypes.ANNOTATION_METHOD : JavaStubElementTypes.METHOD);
|
||||
myReturnType = returnType;
|
||||
myFlags = flags;
|
||||
@@ -114,7 +113,7 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
|
||||
|
||||
@Override
|
||||
public String getDefaultValueText() {
|
||||
return StringRef.toString(myDefaultValueText);
|
||||
return myDefaultValueText;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,7 +157,7 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return StringRef.toString(myName);
|
||||
return myName;
|
||||
}
|
||||
|
||||
public byte getFlags() {
|
||||
@@ -166,7 +165,7 @@ public class PsiMethodStubImpl extends StubBase<PsiMethod> implements PsiMethodS
|
||||
}
|
||||
|
||||
public void setDefaultValueText(final String defaultValueText) {
|
||||
myDefaultValueText = StringRef.fromString(defaultValueText);
|
||||
myDefaultValueText = defaultValueText;
|
||||
}
|
||||
|
||||
public static byte packFlags(boolean isConstructor,
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.psi.stubs;
|
||||
|
||||
import com.intellij.util.io.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -35,10 +36,12 @@ public class StubInputStream extends DataInputStream {
|
||||
myNameStorage = nameStorage;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String readUTFFast() throws IOException {
|
||||
return IOUtil.readUTFFast(myStringIOBuffer, this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public StringRef readName() throws IOException {
|
||||
return DataInputOutputUtil.readNAME(this, myNameStorage);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class DataInputOutputUtil {
|
||||
|
||||
private DataInputOutputUtil() {}
|
||||
|
||||
@Nullable
|
||||
public static StringRef readNAME(@NotNull DataInput record, @NotNull AbstractStringEnumerator nameStore) throws IOException {
|
||||
return StringRef.fromStream(record, nameStore);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user