Skip to content

Commit

Permalink
Create StringBuilder with known size of string
Browse files Browse the repository at this point in the history
  • Loading branch information
heroesleo65 authored and ctongfei committed Jul 7, 2021
1 parent a9c99a0 commit 8036da3
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ protected String speed(ProgressState progress, Duration elapsed) {
}

public String render(ProgressState progress, int maxLength) {
if (maxLength <= 0) {
return "";
}

Instant currTime = Instant.now();
Duration elapsed = Duration.between(progress.startInstant, currTime);
Expand Down Expand Up @@ -126,7 +129,7 @@ public String render(ProgressState progress, int maxLength) {

int length = maxLength - prefixLength - suffixLength;

StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(maxLength);
sb.append(prefix);

// case of indefinite progress bars
Expand Down

0 comments on commit 8036da3

Please sign in to comment.