more accurate memory usage to reduce gc churn

This commit is contained in:
jrandom
2004-06-19 23:11:42 +00:00
committed by zzz
parent 57d24bd948
commit 76c374ef06

View File

@ -27,7 +27,10 @@ class LogRecordFormatter {
private final static int MAX_PRIORITY_LENGTH = 5; private final static int MAX_PRIORITY_LENGTH = 5;
public static String formatRecord(LogManager manager, LogRecord rec) { public static String formatRecord(LogManager manager, LogRecord rec) {
StringBuffer buf = new StringBuffer(1024); int size = 64 + rec.getMessage().length();
if (rec.getThrowable() != null)
size += 512;
StringBuffer buf = new StringBuffer(size);
char format[] = manager._getFormat(); char format[] = manager._getFormat();
for (int i = 0; i < format.length; ++i) { for (int i = 0; i < format.length; ++i) {
switch ((int) format[i]) { switch ((int) format[i]) {
@ -53,7 +56,7 @@ class LogRecordFormatter {
} }
buf.append(NL); buf.append(NL);
if (rec.getThrowable() != null) { if (rec.getThrowable() != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
PrintWriter pw = new PrintWriter(baos, true); PrintWriter pw = new PrintWriter(baos, true);
rec.getThrowable().printStackTrace(pw); rec.getThrowable().printStackTrace(pw);
try { try {