diff --git a/src/main/java/com/gtnewhorizon/gtnhlib/asm/ClassConstantPoolParser.java b/src/main/java/com/gtnewhorizon/gtnhlib/asm/ClassConstantPoolParser.java index 5ce7f5b0..61c04ae3 100644 --- a/src/main/java/com/gtnewhorizon/gtnhlib/asm/ClassConstantPoolParser.java +++ b/src/main/java/com/gtnewhorizon/gtnhlib/asm/ClassConstantPoolParser.java @@ -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