Skip to content

Commit

Permalink
Don't switch Utf8Constant to byte array representation
Browse files Browse the repository at this point in the history
  • Loading branch information
fergal-whyte authored and tvoc-gs committed Nov 28, 2024
1 parent a1282b9 commit 735ec44
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions base/src/main/java/proguard/classfile/constant/Utf8Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Utf8Constant extends Constant {
// Initially, we're storing the UTF-8 bytes in a byte array.
// When the corresponding String is requested, we ditch the array and just
// store the String.
// The StringSharer pass ensures many identical Strings in Utf8Constants are shared. To preserve
// this, the String is never converted back to byte arrays.

// private int u2length;
private byte[] bytes;
Expand All @@ -54,9 +56,10 @@ public void setBytes(byte[] bytes) {

/** Returns the UTF-8 data as an array of bytes. */
public byte[] getBytes() {
switchToByteArrayRepresentation();

return bytes;
if (bytes != null) {
return bytes;
}
return StringUtil.getModifiedUtf8Bytes(string);
}

/** Initializes the UTF-8 data with a String. */
Expand Down Expand Up @@ -91,14 +94,6 @@ public void accept(Clazz clazz, ConstantVisitor constantVisitor) {

// Small utility methods.

/** Switches to a byte array representation of the UTF-8 data. */
private void switchToByteArrayRepresentation() {
if (bytes == null) {
bytes = StringUtil.getModifiedUtf8Bytes(string);
string = null;
}
}

/** Switches to a String representation of the UTF-8 data. */
private void switchToStringRepresentation() {
if (string == null) {
Expand Down

0 comments on commit 735ec44

Please sign in to comment.