From f1b5bb2b69cc2c936532f848095608193589898f Mon Sep 17 00:00:00 2001 From: Peter Lamby Date: Mon, 4 Jul 2022 08:41:57 +0200 Subject: [PATCH] WICKET-6993 - Use buffer to avoid temporary strings --- .../apache/wicket/resource/ResourceUtil.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java index b77630a42a7..ce5a22a406b 100644 --- a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java +++ b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java @@ -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(); } } @@ -228,20 +228,22 @@ public static String readString(IResourceStream resourceStream, Charset charset) /** * Encode the {@code part} in the format ~. * - * 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); } /**