From d6d5435598440b9142e175c32deca4d3dcb03bcb Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 26 Oct 2015 20:42:26 +0100 Subject: [PATCH] faster getUnreachableActionCount --- .../action/fastactionlist/FastActionList.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java index 8efef6c70..55a5a39b7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java @@ -446,6 +446,27 @@ public class FastActionList implements Collection { return count; } + public int getUnreachableActionCountOld(ActionItem jump, ActionItem jumpTarget) { + ActionItem item = firstItem; + if (item == null) { + return 0; + } + + updateReachableFlagsOld(jump, jumpTarget); + jump.reachable = 0; + + int count = 0; + do { + if (item.reachable == 0) { + count++; + } + + item = item.next; + } while (item != firstItem); + + return count; + } + private void clearReachableFlags() { ActionItem item = firstItem; if (item == null) { @@ -477,6 +498,69 @@ public class FastActionList implements Collection { clearReachableFlags(); + firstItem.reachable = 1; + ActionItem firstItem2 = firstItem; + boolean modified = true; + while (modified) { + modified = false; + ActionItem item = firstItem2; + do { + ActionItem next = item.next; + //ActionItem alternativeNext = null; + Action action = item.action; + if (item.reachable == 1) { + item.reachable = 2; + modified = true; + + if (item == firstItem2) { + firstItem2 = next; + } + + if (item == jump) { + if (jumpTarget.reachable == 0) { + jumpTarget.reachable = 1; + //alternativeNext = jumpTarget; + } + } else { + + if (!action.isExit() && !(action instanceof ActionJump)) { + if (next.reachable == 0) { + next.reachable = 1; + } + } + + if (action instanceof GraphSourceItemContainer) { + for (ActionItem lastActionItem : item.getContainerLastActions()) { + if (lastActionItem != null && lastActionItem.next != null && lastActionItem.next.reachable == 0) { + lastActionItem.next.reachable = 1; + //alternativeNext = lastActionItem.next; + } + } + } + + ActionItem target = item.getJumpTarget(); + if (target != null) { + if (target.reachable == 0) { + target.reachable = 1; + //alternativeNext = target; + } + } + } + } + + //item = alternativeNext == null || next.reachable == 1 ? next : alternativeNext; + item = next; + } while (item != firstItem); + } + } + + private void updateReachableFlagsOld(ActionItem jump, ActionItem jumpTarget) { + if (firstItem == null) { + return; + } + + clearReachableFlags(); + firstItem.reachable = 1; boolean modified = true; while (modified) {