Use Long.parseLong(CharSequence,...) to avoid intermediate String creation
Where possible, switch to the Long.parseLong variant that accepts a start and end index for the supplied CharSequence, thus avoiding making unnecessary copies of the String input. Closes gh-30710
This commit is contained in:
committed by
Sam Brannen
parent
af1c06917d
commit
01e90bbd0e
@@ -239,11 +239,11 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
||||
|
||||
public long[] getHeartbeat() {
|
||||
String rawValue = getFirstNativeHeader(STOMP_HEARTBEAT_HEADER);
|
||||
String[] rawValues = StringUtils.split(rawValue, ",");
|
||||
if (rawValues == null) {
|
||||
int pos = rawValue != null ? rawValue.indexOf(',') : -1;
|
||||
if (pos == -1) {
|
||||
return Arrays.copyOf(DEFAULT_HEARTBEAT, 2);
|
||||
}
|
||||
return new long[] {Long.parseLong(rawValues[0]), Long.parseLong(rawValues[1])};
|
||||
return new long[] {Long.parseLong(rawValue, 0, pos, 10), Long.parseLong(rawValue, pos + 1, rawValue.length(), 10)};
|
||||
}
|
||||
|
||||
public void setAcceptVersion(String acceptVersion) {
|
||||
|
||||
@@ -280,11 +280,11 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
|
||||
@Nullable
|
||||
public long[] getHeartbeat() {
|
||||
String rawValue = getFirst(HEARTBEAT);
|
||||
String[] rawValues = StringUtils.split(rawValue, ",");
|
||||
if (rawValues == null) {
|
||||
int pos = rawValue != null ? rawValue.indexOf(',') : -1;
|
||||
if (pos == -1) {
|
||||
return null;
|
||||
}
|
||||
return new long[] {Long.parseLong(rawValues[0]), Long.parseLong(rawValues[1])};
|
||||
return new long[] {Long.parseLong(rawValue, 0, pos, 10), Long.parseLong(rawValue, pos + 1, rawValue.length(), 10)};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user