Skip to content

Commit 23c494c

Browse files
committed
代码优化
1 parent 67fbc5e commit 23c494c

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

snail/src/main/java/com/acgist/snail/utils/Performance.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ protected final void log(Object message) {
3939
* @param args 日志参数
4040
*/
4141
protected final void log(String message, Object ... args) {
42-
if(message == null) {
42+
if(args == null) {
43+
return;
44+
}
45+
int argLength = args.length;
46+
if(message == null && argLength != 0) {
4347
message = "{}";
48+
if(argLength > 1) {
49+
message += "-{}".repeat(argLength - 1);
50+
}
4451
}
4552
LOGGER.info(message, args);
4653
}
@@ -62,12 +69,7 @@ protected final long costed() {
6269
final long time = System.currentTimeMillis();
6370
final long costed = time - this.costTime.getAndSet(time);
6471
if(LOGGER.isInfoEnabled()) {
65-
LOGGER.info("""
66-
消耗时间(毫秒):{}
67-
消耗时间(秒):{}""",
68-
costed,
69-
costed / SystemConfig.ONE_SECOND_MILLIS
70-
);
72+
LOGGER.info("消耗时间(毫秒-秒):{}-{}", costed, costed / SystemConfig.ONE_SECOND_MILLIS);
7173
}
7274
return costed;
7375
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.acgist.snail.utils;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
class PerformanceTest extends Performance {
6+
7+
@Test
8+
void testLog() {
9+
this.log(null);
10+
this.log("1");
11+
this.log(null, "1");
12+
this.log(null, null, null);
13+
this.log(null, new Object[] { null });
14+
this.log(null, new Object[] { null, null });
15+
this.log(null, new Object[] {});
16+
this.log(null, "1", "2", 3);
17+
}
18+
19+
}

0 commit comments

Comments
 (0)