Skip to content

Commit 7fbb853

Browse files
committed
Optimize ExitStatus#addExitDescription
Optimize ExitStatus#addExitDescription by reducing string allocations through: - avoid string allocation when the current description is empty - avoid string allocation when the given description is empty - avoid intermediate string allocation by allocating the correct buffer size
1 parent 4d67858 commit 7fbb853

File tree

1 file changed

+8
-7
lines changed
  • spring-batch-core/src/main/java/org/springframework/batch/core

1 file changed

+8
-7
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/ExitStatus.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,19 @@ public boolean isRunning() {
244244
* description
245245
*/
246246
public ExitStatus addExitDescription(String description) {
247-
StringBuilder buffer = new StringBuilder();
248-
boolean changed = StringUtils.hasText(description) && !exitDescription.equals(description);
249247
if (StringUtils.hasText(exitDescription)) {
250-
buffer.append(exitDescription);
251-
if (changed) {
248+
if (StringUtils.hasText(description) && !exitDescription.equals(description)) {
249+
StringBuilder buffer = new StringBuilder(description.length() + 2 + exitDescription.length());
250+
buffer.append(exitDescription);
252251
buffer.append("; ");
252+
buffer.append(description);
253+
return new ExitStatus(exitCode, buffer.toString());
253254
}
255+
return this;
254256
}
255-
if (changed) {
256-
buffer.append(description);
257+
else {
258+
return new ExitStatus(exitCode, description);
257259
}
258-
return new ExitStatus(exitCode, buffer.toString());
259260
}
260261

261262
/**

0 commit comments

Comments
 (0)