From 5a1edc83df2b4842cdc06845d595dde850e97d34 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 15 Apr 2011 15:21:25 +0200 Subject: [PATCH] less parseMembers() invocations --- .../classParsing/ClassFileReader.java | 56 +++++++------------ .../intellij/compiler/impl/CompileDriver.java | 2 +- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/classParsing/ClassFileReader.java b/java/compiler/impl/src/com/intellij/compiler/classParsing/ClassFileReader.java index c8c4bae7334e..9d92c03e0781 100644 --- a/java/compiler/impl/src/com/intellij/compiler/classParsing/ClassFileReader.java +++ b/java/compiler/impl/src/com/intellij/compiler/classParsing/ClassFileReader.java @@ -28,7 +28,6 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.cls.BytePointer; import com.intellij.util.cls.ClsFormatException; import com.intellij.util.cls.ClsUtil; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +53,8 @@ public class ClassFileReader { private final SymbolTable mySymbolTable; private AnnotationConstantValue[] myRuntimeVisibleAnnotations; private AnnotationConstantValue[] myRuntimeInvisibleAnnotations; - @NonNls private static final String CONSTRUCTOR_NAME = ""; + private static final String CONSTRUCTOR_NAME = ""; + private boolean myParsingDone; public ClassFileReader(@NotNull File file, SymbolTable symbolTable, @Nullable final byte[] fileContent) { mySymbolTable = symbolTable; @@ -72,20 +72,19 @@ public class ClassFileReader { } public MethodInfo[] getMethods() throws ClsFormatException{ - if (myMethods == null) { - parseMembers(); - } + parseMembers(); return myMethods.toArray(new MethodInfo[myMethods.size()]); } public FieldInfo[] getFields() throws ClsFormatException{ - if (myFields == null) { - parseMembers(); - } + parseMembers(); return myFields.toArray(new FieldInfo[myFields.size()]); } private void parseMembers() throws ClsFormatException { + if (myParsingDone) { + return; + } initConstantPool(); myMethods = new ArrayList(); myFields = new ArrayList(); @@ -121,6 +120,7 @@ public class ClassFileReader { myGenericSignature = attributeTable.genericSignature; myRuntimeVisibleAnnotations = attributeTable.runtimeVisibleAnnotations; myRuntimeInvisibleAnnotations = attributeTable.runtimeInvisibleAnnotations; + myParsingDone = true; } private String getSymbol(final int id) throws ClsFormatException { @@ -253,43 +253,27 @@ public class ClassFileReader { public String getSourceFileName() throws ClsFormatException { - if (mySourceFileName == null) { - parseMembers(); - if (mySourceFileName == null) { - mySourceFileName = ""; - } - } - return mySourceFileName; + parseMembers(); + final String fName = mySourceFileName; + return fName != null? fName : ""; } public String getGenericSignature() throws ClsFormatException { - if (myGenericSignature == null) { - parseMembers(); - if (myGenericSignature == null) { - myGenericSignature = ""; - } - } - return myGenericSignature.length() == 0 ? null : myGenericSignature; + parseMembers(); + final String genericSignature = myGenericSignature; + return genericSignature != null && !genericSignature.isEmpty() ? genericSignature : null; } public AnnotationConstantValue[] getRuntimeVisibleAnnotations() throws ClsFormatException { - if (myRuntimeVisibleAnnotations == null) { - parseMembers(); - if (myRuntimeVisibleAnnotations == null) { - myRuntimeVisibleAnnotations = AnnotationConstantValue.EMPTY_ARRAY; - } - } - return myRuntimeVisibleAnnotations; + parseMembers(); + final AnnotationConstantValue[] annotations = myRuntimeVisibleAnnotations; + return annotations != null? annotations : AnnotationConstantValue.EMPTY_ARRAY; } public AnnotationConstantValue[] getRuntimeInvisibleAnnotations() throws ClsFormatException { - if (myRuntimeInvisibleAnnotations == null) { - parseMembers(); - if (myRuntimeInvisibleAnnotations == null) { - myRuntimeInvisibleAnnotations = AnnotationConstantValue.EMPTY_ARRAY; - } - } - return myRuntimeInvisibleAnnotations; + parseMembers(); + final AnnotationConstantValue[] annotations = myRuntimeInvisibleAnnotations; + return annotations != null? annotations : AnnotationConstantValue.EMPTY_ARRAY; } private boolean isInterface(){ diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index e884f85dbfd8..b4321a5b9322 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -190,7 +190,7 @@ public class CompileDriver { } scope = addAdditionalRoots(scope, ALL_EXCEPT_SOURCE_PROCESSING); - final CompilerTask task = new CompilerTask(myProject, true, "", true); + final CompilerTask task = new CompilerTask(myProject, true, "Classes up-to-date check", true); final CompileContextImpl compileContext = new CompileContextImpl(myProject, task, scope, createDependencyCache(), true, false); checkCachesVersion(compileContext, ((PersistentFS)ManagingFS.getInstance()).getCreationTimestamp());