Avoid unnecessary allocations in StompDecoder#unescape

Closes gh-29443
This commit is contained in:
Christoph Dreis 2022-11-07 20:47:02 +01:00 committed by Sam Brannen
parent f4b3333fa8
commit 55b258f2de
1 changed files with 5 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -264,9 +264,12 @@ public class StompDecoder {
* <a href="https://stomp.github.io/stomp-specification-1.2.html#Value_Encoding">"Value Encoding"</a>.
*/
private String unescape(String inString) {
int index = inString.indexOf('\\');
if (index == -1) {
return inString;
}
StringBuilder sb = new StringBuilder(inString.length());
int pos = 0; // position in the old string
int index = inString.indexOf('\\');
while (index >= 0) {
sb.append(inString, pos, index);