Skip to content

Commit b5bfacc

Browse files
thelproadbeiwei30
authored andcommitted
Optimize StringBuilder#append (apache#4872)
1 parent 171ed25 commit b5bfacc

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/status/ThreadPoolStatusChecker.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,9 @@ public Status check() {
5656
if (msg.length() > 0) {
5757
msg.append(";");
5858
}
59-
msg.append("Pool status:" + lvl
60-
+ ", max:" + tp.getMaximumPoolSize()
61-
+ ", core:" + tp.getCorePoolSize()
62-
+ ", largest:" + tp.getLargestPoolSize()
63-
+ ", active:" + tp.getActiveCount()
64-
+ ", task:" + tp.getTaskCount()
65-
+ ", service port: " + port);
59+
msg.append("Pool status:").append(lvl).append(", max:").append(tp.getMaximumPoolSize()).append(", core:")
60+
.append(tp.getCorePoolSize()).append(", largest:").append(tp.getLargestPoolSize()).append(", active:")
61+
.append(tp.getActiveCount()).append(", task:").append(tp.getTaskCount()).append(", service port: ").append(port);
6662
}
6763
}
6864
return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/ChangeTelnetHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public String telnet(Channel channel, String message) {
4141
if ("/".equals(message) || "..".equals(message)) {
4242
String service = (String) channel.getAttribute(SERVICE_KEY);
4343
channel.removeAttribute(SERVICE_KEY);
44-
buf.append("Cancelled default service " + service + ".");
44+
buf.append("Cancelled default service ").append(service).append(".");
4545
} else {
4646
boolean found = false;
4747
for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) {
@@ -54,9 +54,9 @@ public String telnet(Channel channel, String message) {
5454
}
5555
if (found) {
5656
channel.setAttribute(SERVICE_KEY, message);
57-
buf.append("Used the " + message + " as default.\r\nYou can cancel default service by command: cd /");
57+
buf.append("Used the ").append(message).append(" as default.\r\nYou can cancel default service by command: cd /");
5858
} else {
59-
buf.append("No such service " + message);
59+
buf.append("No such service ").append(message);
6060
}
6161
}
6262
return buf.toString();

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/CountTelnetHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public String telnet(final Channel channel, String message) {
4949
}
5050
StringBuilder buf = new StringBuilder();
5151
if (service != null && service.length() > 0) {
52-
buf.append("Use default service " + service + ".\r\n");
52+
buf.append("Use default service ").append(service).append(".\r\n");
5353
}
5454
String[] parts = message.split("\\s+");
5555
String method;
@@ -112,7 +112,7 @@ public void run() {
112112
thread.start();
113113
}
114114
} else {
115-
buf.append("No such service " + service);
115+
buf.append("No such service ").append(service);
116116
}
117117
return buf.toString();
118118
}

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private void printSelectMessage(StringBuilder buf, List<Method> methods) {
237237
buf.append("Methods:\r\n");
238238
for (int i = 0; i < methods.size(); i++) {
239239
Method method = methods.get(i);
240-
buf.append((i + 1) + ". " + method.getName() + "(");
240+
buf.append(i + 1).append(". ").append(method.getName()).append("(");
241241
Class<?>[] parameterTypes = method.getParameterTypes();
242242
for (int n = 0; n < parameterTypes.length; n++) {
243243
buf.append(parameterTypes[n].getSimpleName());

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/LogTelnetHandler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public String telnet(Channel channel, String message) {
7070
bb.flip();
7171
String content = new String(bb.array()).replace("<", "&lt;")
7272
.replace(">", "&gt;").replace("\n", "<br/><br/>");
73-
buf.append("\r\ncontent:" + content);
73+
buf.append("\r\ncontent:").append(content);
7474

75-
buf.append("\r\nmodified:" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
76-
.format(new Date(file.lastModified()))));
77-
buf.append("\r\nsize:" + size + "\r\n");
75+
buf.append("\r\nmodified:").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
76+
.format(new Date(file.lastModified())));
77+
buf.append("\r\nsize:").append(size).append("\r\n");
7878
} catch (Exception e) {
7979
buf.append(e.getMessage());
8080
}
@@ -84,8 +84,8 @@ public String telnet(Channel channel, String message) {
8484
}
8585
}
8686
}
87-
buf.append("\r\nCURRENT LOG LEVEL:" + LoggerFactory.getLevel())
88-
.append("\r\nCURRENT LOG APPENDER:" + (file == null ? "console" : file.getAbsolutePath()));
87+
buf.append("\r\nCURRENT LOG LEVEL:").append(LoggerFactory.getLevel()).append("\r\nCURRENT LOG APPENDER:")
88+
.append(file == null ? "console" : file.getAbsolutePath());
8989
return buf.toString();
9090
}
9191

dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/telnet/PortTelnetHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public String telnet(Channel channel, String message) {
5858
buf.append("\r\n");
5959
}
6060
if (detail) {
61-
buf.append(server.getUrl().getProtocol() + "://" + server.getUrl().getAddress());
61+
buf.append(server.getUrl().getProtocol()).append("://").append(server.getUrl().getAddress());
6262
} else {
6363
buf.append(server.getUrl().getPort());
6464
}
@@ -79,13 +79,13 @@ public String telnet(Channel channel, String message) {
7979
buf.append("\r\n");
8080
}
8181
if (detail) {
82-
buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress());
82+
buf.append(c.getRemoteAddress()).append(" -> ").append(c.getLocalAddress());
8383
} else {
8484
buf.append(c.getRemoteAddress());
8585
}
8686
}
8787
} else {
88-
buf.append("No such port " + port);
88+
buf.append("No such port ").append(port);
8989
}
9090
}
9191
return buf.toString();

0 commit comments

Comments
 (0)