From d505a9065413ef3bc024c60b6202586f40631cf8 Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Mon, 7 Nov 2022 20:47:02 +0100 Subject: [PATCH] Avoid allocations from StompDecoder#unescape --- .../springframework/messaging/simp/stomp/StompDecoder.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index c183803423e4..234d9917e06f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 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 @@ private void readHeaders(ByteBuffer byteBuffer, StompHeaderAccessor headerAccess * "Value Encoding". */ 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);