java patches for string concatonation

Tom Tromey tromey@cygnus.com
Sun Jan 9 17:13:00 GMT 2000


Anthony> When gcj sees string concatonation with the "+" operator, and
Anthony> the first operand (op1) is either a String reference or a
Anthony> string literal, we emit a call to `new StringBuffer(op1)' and
Anthony> append op2.  If op1 is null then this constructor should be
Anthony> throwing a NullPointerException, however, right now it is
Anthony> filling the buffer with "null".

The libgcj side is fine provided that the compiler side goes in too.

Eventually I think we should stop using StringBuffer to implement
string concatenation, and instead use something faster.  For example,
we could use a StringBuffer-like class (that would also be used by the
StringBuffer implementation) which does not have any synchronization.

We could even allocate the buffer on the stack in some siuations, or
perhaps partially allocate it on the stack (and revert to the heap on
overflow).

Tom


More information about the Java-patches mailing list