Slightly tweaked initial string buffer size.

This commit is contained in:
hns 2002-09-17 22:39:26 +00:00
parent 0c4ae4da46
commit d4f379a54d

View file

@ -80,6 +80,8 @@ public final class ResponseTrans implements Externalizable {
*/ */
public transient String title, head, body, message, error; public transient String title, head, body, message, error;
static final int INITIAL_BUFFER_SIZE = 2048;
/** /**
* JavaScript object to make the values Map accessible to * JavaScript object to make the values Map accessible to
* script code as res.data * script code as res.data
@ -131,7 +133,7 @@ public final class ResponseTrans implements Externalizable {
/** /**
* This is called before a template is rendered as string (xxx_as_string) to redirect the output * This is called before a skin is rendered as string (renderSkinAsString) to redirect the output
* to a new string buffer. * to a new string buffer.
*/ */
public void pushStringBuffer () { public void pushStringBuffer () {
@ -139,7 +141,7 @@ public final class ResponseTrans implements Externalizable {
buffers = new Stack(); buffers = new Stack();
if (buffer != null) if (buffer != null)
buffers.push (buffer); buffers.push (buffer);
buffer = new StringBuffer (128); buffer = new StringBuffer (64);
} }
/** /**
@ -161,22 +163,25 @@ public final class ResponseTrans implements Externalizable {
} }
/** /**
* Append a string to the response unchanged. * Append a string to the response unchanged. This is often called
* at the end of a request to write out the whole page, so if buffer
* is uninitialized we just set it to the string argument.
*/ */
public void write (Object what) { public void write (Object what) {
if (what != null) { if (what != null) {
String str = what.toString ();
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (Math.max (str.length()+100, INITIAL_BUFFER_SIZE));
buffer.append (what.toString ()); buffer.append (what.toString ());
} }
} }
/** /**
* Utility function that appends a <br> to whatever is written * Utility function that appends a <br> to whatever is written.
*/ */
public void writeln (Object what) { public void writeln (Object what) {
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (INITIAL_BUFFER_SIZE);
if (what != null) if (what != null)
buffer.append (what.toString ()); buffer.append (what.toString ());
buffer.append ("<br />\r\n"); buffer.append ("<br />\r\n");
@ -187,7 +192,7 @@ public final class ResponseTrans implements Externalizable {
*/ */
public void writeCharArray (char[] c, int start, int length) { public void writeCharArray (char[] c, int start, int length) {
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (Math.max (length, INITIAL_BUFFER_SIZE));
buffer.append (c, start, length); buffer.append (c, start, length);
} }
@ -207,9 +212,10 @@ public final class ResponseTrans implements Externalizable {
*/ */
public void encode (Object what) { public void encode (Object what) {
if (what != null) { if (what != null) {
String str = what.toString ();
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (Math.max (str.length()+100, INITIAL_BUFFER_SIZE));
HtmlEncoder.encodeAll (what.toString (), buffer); HtmlEncoder.encodeAll (str, buffer);
} }
} }
@ -219,9 +225,10 @@ public final class ResponseTrans implements Externalizable {
*/ */
public void format (Object what) { public void format (Object what) {
if (what != null) { if (what != null) {
String str = what.toString ();
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (Math.max (str.length()+100, INITIAL_BUFFER_SIZE));
HtmlEncoder.encode (what.toString (), buffer); HtmlEncoder.encode (str, buffer);
} }
} }
@ -232,9 +239,10 @@ public final class ResponseTrans implements Externalizable {
*/ */
public void encodeXml (Object what) { public void encodeXml (Object what) {
if (what != null) { if (what != null) {
String str = what.toString ();
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (Math.max (str.length()+100, INITIAL_BUFFER_SIZE));
HtmlEncoder.encodeXml (what.toString (), buffer); HtmlEncoder.encodeXml (str, buffer);
} }
} }
@ -244,18 +252,19 @@ public final class ResponseTrans implements Externalizable {
*/ */
public void encodeForm (Object what) { public void encodeForm (Object what) {
if (what != null) { if (what != null) {
String str = what.toString ();
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (Math.max (str.length()+100, INITIAL_BUFFER_SIZE));
HtmlEncoder.encodeAll (what.toString (), buffer, false); HtmlEncoder.encodeAll (str, buffer, false);
} }
} }
public void append (String what) { public void append (String str) {
if (what != null) { if (str != null) {
if (buffer == null) if (buffer == null)
buffer = new StringBuffer (512); buffer = new StringBuffer (Math.max (str.length(), INITIAL_BUFFER_SIZE));
buffer.append (what); buffer.append (str);
} }
} }