You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/11/24 13:32:58 UTC

[commons-bcel] branch master updated: Make org.apache.bcel.generic.SWITCH.match final

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git


The following commit(s) were added to refs/heads/master by this push:
     new eef6bb9c Make org.apache.bcel.generic.SWITCH.match final
eef6bb9c is described below

commit eef6bb9cfb6815a9d445849dd512959bbf416c61
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Thu Nov 24 08:32:54 2022 -0500

    Make org.apache.bcel.generic.SWITCH.match final
    
    Remove unused org.apache.bcel.generic.SWITCH.targets
---
 src/main/java/org/apache/bcel/generic/SWITCH.java | 71 +++++++++++------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/src/main/java/org/apache/bcel/generic/SWITCH.java b/src/main/java/org/apache/bcel/generic/SWITCH.java
index 08c9d67f..ec55a058 100644
--- a/src/main/java/org/apache/bcel/generic/SWITCH.java
+++ b/src/main/java/org/apache/bcel/generic/SWITCH.java
@@ -24,6 +24,40 @@ import java.util.Arrays;
  */
 public final class SWITCH implements CompoundInstruction {
 
+    /**
+     * Sorts match and targets array with QuickSort.
+     */
+    private static void sort(final int l, final int r, final int[] match, final InstructionHandle[] targets) {
+        int i = l;
+        int j = r;
+        int h;
+        final int m = match[l + r >>> 1];
+        InstructionHandle h2;
+        do {
+            while (match[i] < m) {
+                i++;
+            }
+            while (m < match[j]) {
+                j--;
+            }
+            if (i <= j) {
+                h = match[i];
+                match[i] = match[j];
+                match[j] = h; // Swap elements
+                h2 = targets[i];
+                targets[i] = targets[j];
+                targets[j] = h2; // Swap instructions, too
+                i++;
+                j--;
+            }
+        } while (i <= j);
+        if (l < j) {
+            sort(l, j, match, targets);
+        }
+        if (i < r) {
+            sort(i, r, match, targets);
+        }
+    }
     private final int[] match;
     private final Select instruction;
     private final int matchLength;
@@ -50,7 +84,7 @@ public final class SWITCH implements CompoundInstruction {
         if ((matchLength = match.length) < 2) {
             instruction = new TABLESWITCH(match, targets, target);
         } else {
-            sort(0, matchLength - 1, targetsCopy);
+            sort(0, matchLength - 1, matchCopy, targetsCopy);
             if (matchIsOrdered(maxGap)) {
                 final int maxSize = matchLength + matchLength * maxGap;
                 final int[] mVec = new int[maxSize];
@@ -100,39 +134,4 @@ public final class SWITCH implements CompoundInstruction {
         }
         return true;
     }
-
-    /**
-     * Sort match and targets array with QuickSort.
-     */
-    private void sort(final int l, final int r, final InstructionHandle[] targets) {
-        int i = l;
-        int j = r;
-        int h;
-        final int m = match[l + r >>> 1];
-        InstructionHandle h2;
-        do {
-            while (match[i] < m) {
-                i++;
-            }
-            while (m < match[j]) {
-                j--;
-            }
-            if (i <= j) {
-                h = match[i];
-                match[i] = match[j];
-                match[j] = h; // Swap elements
-                h2 = targets[i];
-                targets[i] = targets[j];
-                targets[j] = h2; // Swap instructions, too
-                i++;
-                j--;
-            }
-        } while (i <= j);
-        if (l < j) {
-            sort(l, j, targets);
-        }
-        if (i < r) {
-            sort(i, r, targets);
-        }
-    }
 }