Skip to content

Commit

Permalink
move equals
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jul 31, 2024
1 parent 6a59f14 commit 545eb86
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
27 changes: 1 addition & 26 deletions src/main/java/xyz/wagyourtail/jvmdg/ClassDowngrader.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;
import xyz.wagyourtail.jvmdg.asm.ASMUtils;
import xyz.wagyourtail.jvmdg.classloader.DowngradingClassLoader;
import xyz.wagyourtail.jvmdg.cli.Flags;
Expand All @@ -25,12 +23,10 @@
import java.io.*;
import java.lang.instrument.IllegalClassFormatException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;

public class ClassDowngrader implements Closeable {
/**
Expand Down Expand Up @@ -377,7 +373,7 @@ public ClassNode apply(String s) {
byte[] currentVal = current.get(key);
byte[] vsVal = vs.getValue();
// equal after version info
if (!equals(currentVal, 8, currentVal.length, vsVal, 8, vsVal.length)) {
if (!Utils.equals(currentVal, 8, currentVal.length, vsVal, 8, vsVal.length)) {
current.put(key, vsVal);
outputs.put("META-INF/versions/" + vs.getKey() + "/" + key, vsVal);
}
Expand All @@ -403,27 +399,6 @@ public ClassNode apply(String s) {
return outputs;
}

public static boolean equals(
byte[] a, int aFromIndex, int aToIndex,
byte[] b, int bFromIndex, int bToIndex
) {
int aLength = aToIndex - aFromIndex;
int bLength = bToIndex - bFromIndex;
if (aLength != bLength) {
return false;
}
if (aLength == 0) {
return true;
}
for (int i = 0; i < aLength; i++) {
if (a[aFromIndex + i] != b[bFromIndex + i]) {
return false;
}
}
return true;
}


public byte[] classNodeToBytes(@NotNull final ClassNode node) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
node.accept(cw);
Expand Down
19 changes: 19 additions & 0 deletions src/shared/java/xyz/wagyourtail/jvmdg/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,23 @@ public static <T extends Throwable> void sneakyThrow(Throwable t) throws T {
throw (T) t;
}

public static boolean equals(
byte[] a, int aFromIndex, int aToIndex,
byte[] b, int bFromIndex, int bToIndex
) {
int aLength = aToIndex - aFromIndex;
int bLength = bToIndex - bFromIndex;
if (aLength != bLength) {
return false;
}
if (aLength == 0) {
return true;
}
for (int i = 0; i < aLength; i++) {
if (a[aFromIndex + i] != b[bFromIndex + i]) {
return false;
}
}
return true;
}
}

0 comments on commit 545eb86

Please sign in to comment.