Skip to content

Commit

Permalink
WICKET-6993 - Use buffer to avoid temporary strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Lamby committed Jul 4, 2022
1 parent 8537a97 commit f1b5bb2
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ public static String encodeResourceReferenceAttributes(ResourceReference.UrlAttr
}
else
{
StringBuilder res = new StringBuilder(32);
res.append(encodeStringPart(attributes.getLocale() == null ? null : attributes.getLocale().toString()));
res.append(encodeStringPart(attributes.getStyle()));
res.append(encodeStringPart(attributes.getVariation()));
return res.toString();
StringBuilder buffer = new StringBuilder(32);
encodeStringPart(attributes.getLocale() == null ? null : attributes.getLocale().toString(), buffer);
encodeStringPart(attributes.getStyle(), buffer);
encodeStringPart(attributes.getVariation(), buffer);
return buffer.toString();
}
}

Expand Down Expand Up @@ -228,20 +228,22 @@ public static String readString(IResourceStream resourceStream, Charset charset)
/**
* Encode the {@code part} in the format <string length encoded in base ten ASCII>~<string data>.
*
* If the {@code part} is {@code null} the special value {@link #NULL_VALUE} is returned;
* If the {@code part} is {@code null} the special value {@link #NULL_VALUE} is used;
*
* @param part
* The string to encode
* @return The encoded string
* The string to encode.
* @param buffer
* The buffer into which the {@code part} is encoded.
* @return The {@code buffer} for chaining.
*/
static String encodeStringPart(String part)
static StringBuilder encodeStringPart(String part, StringBuilder buffer)
{
if (part == null) {
return NULL_VALUE;
return buffer.append(NULL_VALUE);
}

int length = part.length();
return length + "~" + part;
return buffer.append(length).append('~').append(part);
}

/**
Expand Down

0 comments on commit f1b5bb2

Please sign in to comment.