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/12/08 16:15:43 UTC

[commons-compress] 12/38: Convert cascading if/else to switch

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-compress.git

commit 94a4ad22283d1a3c1753b73d3483114a238a1e76
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 8 11:05:31 2022 -0500

    Convert cascading if/else to switch
---
 .../compress/harmony/pack200/ClassBands.java       | 29 ++++++++++++++--------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
index 593c59bd..dfc026a7 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
@@ -294,22 +294,31 @@ public class ClassBands extends BandSet {
 			final int numHandlers = codeHandlerCount.get(i - removed);
 			final int maxLocals = codeMaxLocals.get(i - removed);
 			final int maxStack = codeMaxStack.get(i - removed);
-			if (numHandlers == 0) {
-				final int header = maxLocals * 12 + maxStack + 1;
-				if (header < 145 && maxStack < 12) {
+			switch (numHandlers) {
+            case 0: {
+                final int header = maxLocals * 12 + maxStack + 1;
+                if (header < 145 && maxStack < 12) {
 					codeHeaders[i] = header;
 				}
-			} else if (numHandlers == 1) {
-				final int header = maxLocals * 8 + maxStack + 145;
-				if (header < 209 && maxStack < 8) {
+                break;
+            }
+            case 1: {
+                final int header = maxLocals * 8 + maxStack + 145;
+                if (header < 209 && maxStack < 8) {
 					codeHeaders[i] = header;
 				}
-			} else if (numHandlers == 2) {
-				final int header = maxLocals * 7 + maxStack + 209;
-				if (header < 256 && maxStack < 7) {
+                break;
+            }
+            case 2: {
+                final int header = maxLocals * 7 + maxStack + 209;
+                if (header < 256 && maxStack < 7) {
 					codeHeaders[i] = header;
 				}
-			}
+                break;
+            }
+            default:
+                break;
+            }
 			if (codeHeaders[i] != 0) { // Remove the redundant values from
 										// codeHandlerCount, codeMaxLocals and
 										// codeMaxStack