add back and mark deprecated ClassConstantPoolParser#addString method (#291)

This commit is contained in:
Alexdoru authored and GitHub committed 2026-02-25 17:11:26 +00:00
1 parent a0d7643ed1
commit d1abde1426
1 file changed
+11 -4
@@ -23,6 +23,7 @@
package com.gtnewhorizon.gtnhlib.asm;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
/**
* Using this class to search for a (single) String reference is > 40 times faster than parsing a class with a
@@ -74,10 +75,7 @@ public final class ClassConstantPoolParser {
}
}
// the strings to search should not be resized
// during runtime to avoid becoming less performant
// than using ASM directly
private final byte[][] BYTES_TO_SEARCH;
private byte[][] BYTES_TO_SEARCH;
public ClassConstantPoolParser(String... strings) {
BYTES_TO_SEARCH = new byte[strings.length][];
@@ -86,6 +84,15 @@ public final class ClassConstantPoolParser {
}
}
/// the strings to search should not be resized
/// during runtime to avoid becoming less performant
/// than using ASM directly
@Deprecated
public void addString(String string) {
BYTES_TO_SEARCH = Arrays.copyOf(BYTES_TO_SEARCH, BYTES_TO_SEARCH.length + 1);
BYTES_TO_SEARCH[BYTES_TO_SEARCH.length - 1] = string.getBytes(StandardCharsets.UTF_8);
}
/**
* Returns true if the constant pool of the class represented by this byte array contains one of the Strings we are
* looking for