Skip to content

Commit

Permalink
Cleaned up allocation for string builder in utf8mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Asbury committed Oct 22, 2018
1 parent a27c693 commit 98a8928
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/io/nats/client/impl/NatsMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ static int copy(byte[] dest, int pos, String toCopy) {
this.data = data;

if (utf8mode) {
StringBuilder protocolStringBuilder = new StringBuilder((2 * subject.length()) + 20); // guess a size based on replyTO = subject
int subjectSize = subject.length() * 2;
int replySize = (replyTo != null) ? replyTo.length() * 2 : 0;
StringBuilder protocolStringBuilder = new StringBuilder(4 + subjectSize + 1 + replySize + 1);
protocolStringBuilder.append(PUB_SPACE);
protocolStringBuilder.append(subject);
protocolStringBuilder.append(SPACE);
Expand Down

0 comments on commit 98a8928

Please sign in to comment.