提交 e74aac10 authored 作者: Andrei Tokar's avatar Andrei Tokar

reduce garbage creation

上级 8e45edf0
...@@ -300,10 +300,10 @@ public class Trace { ...@@ -300,10 +300,10 @@ public class Trace {
if (!space) { if (!space) {
buff.append(' '); buff.append(' ');
} }
buff.append("*/"). buff.append("*/");
append(StringUtils.javaEncode(sql)). StringUtils.javaEncode(sql, buff);
append(StringUtils.javaEncode(params)). StringUtils.javaEncode(params, buff);
append(';'); buff.append(';');
sql = buff.toString(); sql = buff.toString();
traceWriter.write(TraceSystem.INFO, module, sql, null); traceWriter.write(TraceSystem.INFO, module, sql, null);
} }
......
...@@ -148,8 +148,13 @@ public class StringUtils { ...@@ -148,8 +148,13 @@ public class StringUtils {
* @return the Java representation * @return the Java representation
*/ */
public static String javaEncode(String s) { public static String javaEncode(String s) {
StringBuilder buff = new StringBuilder(s.length());
javaEncode(s, buff);
return buff.toString();
}
public static void javaEncode(String s, StringBuilder buff) {
int length = s.length(); int length = s.length();
StringBuilder buff = new StringBuilder(length);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
char c = s.charAt(i); char c = s.charAt(i);
switch (c) { switch (c) {
...@@ -202,7 +207,6 @@ public class StringUtils { ...@@ -202,7 +207,6 @@ public class StringUtils {
} }
} }
} }
return buff.toString();
} }
/** /**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论