Skip to content

Commit

Permalink
[Performance] Fix string concatenation in loop (apache#10986)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattisonchao authored Jun 20, 2021
1 parent 7417ca8 commit 8a07538
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.pulsar.proxy.server;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -74,9 +75,11 @@ private void logging(Channel conn, BaseCommand.Type cmdtype, String info, List<R

if (messages != null) {
// lag
for (int i=0; i<messages.size(); i++) {
info = info + "["+ (System.currentTimeMillis() - messages.get(i).getPublishTime()) + "] " + new String(ByteBufUtil.getBytes((messages.get(i)).getData()), "UTF8");
StringBuilder infoBuilder = new StringBuilder(info);
for (RawMessage message : messages) {
infoBuilder.append("[").append(System.currentTimeMillis() - message.getPublishTime()).append("] ").append(new String(ByteBufUtil.getBytes(message.getData()), StandardCharsets.UTF_8));
}
info = infoBuilder.toString();
}
// log conn format is like from source to target
switch (this.connType) {
Expand Down

0 comments on commit 8a07538

Please sign in to comment.