From 51c38d4cd3fcdb27dfc58b730b0cc69ef9e06bdf Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 14 Dec 2012 17:16:27 +0400 Subject: [PATCH] do not store references to all copies (if it's a copy itself) --- .../lang/cfg/pseudocode/InstructionImpl.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java index 3724b47315d..32239a54c84 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/InstructionImpl.java @@ -30,6 +30,7 @@ public abstract class InstructionImpl implements Instruction { private Pseudocode owner; private final Collection previousInstructions = new LinkedHashSet(); private final Collection copies = Sets.newHashSet(); + private Instruction original; protected boolean isDead = false; protected InstructionImpl() { @@ -78,6 +79,12 @@ public abstract class InstructionImpl implements Instruction { @NotNull @Override public Collection getCopies() { + if (original != null) { + Collection originalCopies = Sets.newHashSet(original.getCopies()); + originalCopies.remove(this); + originalCopies.add(original); + return originalCopies; + } return copies; } @@ -85,13 +92,15 @@ public abstract class InstructionImpl implements Instruction { copies.add(instruction); } + private void setOriginal(@NotNull Instruction original) { + assert this.original == null : + "Instruction can't have two originals: this.original = " + this.original + "; new original = " + original; + this.original = original; + } + protected Instruction updateCopyInfo(@NotNull Instruction instruction) { - for (Instruction copy : copies) { - ((InstructionImpl)copy).addCopy(instruction); - ((InstructionImpl)instruction).addCopy(copy); - } addCopy(instruction); - ((InstructionImpl)instruction).addCopy(this); + ((InstructionImpl)instruction).setOriginal(this); return instruction; } }