Skip to content

Commit 5b703c0

Browse files
committed
Cache instruction for creation.
1 parent d0ce160 commit 5b703c0

File tree

1 file changed

+23
-16
lines changed
  • edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis

1 file changed

+23
-16
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Stream.java

+23-16
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public class Stream {
9595

9696
private final MethodInvocation creation;
9797

98+
private Optional<SSAInvokeInstruction> instructionForCreation;
99+
98100
private final MethodDeclaration enclosingMethodDeclaration;
99101

100102
private IR enclosingMethodDeclarationIR;
@@ -419,24 +421,29 @@ public InstanceKey getInstanceKey(Collection<InstanceKey> trackedInstances,
419421

420422
Optional<SSAInvokeInstruction> getInstructionForCreation(EclipseProjectAnalysisEngine<InstanceKey> engine)
421423
throws InvalidClassFileException, IOException, CoreException {
422-
IBytecodeMethod method = (IBytecodeMethod) this.getEnclosingMethodIR(engine).getMethod();
423-
SimpleName methodName = this.getCreation().getName();
424-
425-
for (Iterator<SSAInstruction> it = this.getEnclosingMethodIR(engine).iterateNormalInstructions(); it
426-
.hasNext();) {
427-
SSAInstruction instruction = it.next();
428-
429-
int lineNumberFromIR = getLineNumberFromIR(method, instruction);
430-
int lineNumberFromAST = getLineNumberFromAST(methodName);
431-
432-
if (lineNumberFromIR == lineNumberFromAST) {
433-
// lines from the AST and the IR match. Let's dive a little
434-
// deeper to be more confident of the correspondence.
435-
if (matches(instruction, this.getCreation(), Optional.of(LOGGER)))
436-
return Optional.of((SSAInvokeInstruction) instruction);
424+
if (this.instructionForCreation == null) {
425+
IBytecodeMethod method = (IBytecodeMethod) this.getEnclosingMethodIR(engine).getMethod();
426+
SimpleName methodName = this.getCreation().getName();
427+
428+
for (Iterator<SSAInstruction> it = this.getEnclosingMethodIR(engine).iterateNormalInstructions(); it
429+
.hasNext();) {
430+
SSAInstruction instruction = it.next();
431+
432+
int lineNumberFromIR = getLineNumberFromIR(method, instruction);
433+
int lineNumberFromAST = getLineNumberFromAST(methodName);
434+
435+
if (lineNumberFromIR == lineNumberFromAST) {
436+
// lines from the AST and the IR match. Let's dive a little
437+
// deeper to be more confident of the correspondence.
438+
if (matches(instruction, this.getCreation(), Optional.of(LOGGER))) {
439+
instructionForCreation = Optional.of((SSAInvokeInstruction) instruction);
440+
return instructionForCreation;
441+
}
442+
}
437443
}
444+
instructionForCreation = Optional.empty();
438445
}
439-
return Optional.empty();
446+
return instructionForCreation;
440447
}
441448

442449
private JDTIdentityMapper getJDTIdentifyMapperForCreation() {

0 commit comments

Comments
 (0)