Skip to content

Commit 29e746f

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 656e3f8 commit 29e746f

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
@@ -246,18 +246,19 @@ public boolean isRunning() {
246246
* description.
247247
*/
248248
public ExitStatus addExitDescription(String description) {
249-
StringBuilder buffer = new StringBuilder();
250-
boolean changed = StringUtils.hasText(description) && !exitDescription.equals(description);
251249
if (StringUtils.hasText(exitDescription)) {
252-
buffer.append(exitDescription);
253-
if (changed) {
250+
if (StringUtils.hasText(description) && !exitDescription.equals(description)) {
251+
StringBuilder buffer = new StringBuilder(description.length() + 2 + exitDescription.length());
252+
buffer.append(exitDescription);
254253
buffer.append("; ");
254+
buffer.append(description);
255+
return new ExitStatus(exitCode, buffer.toString());
255256
}
257+
return this;
256258
}
257-
if (changed) {
258-
buffer.append(description);
259+
else {
260+
return new ExitStatus(exitCode, description);
259261
}
260-
return new ExitStatus(exitCode, buffer.toString());
261262
}
262263

263264
/**

0 commit comments

Comments
 (0)