org.eclipse.xtend.backend.common
Class EfficientLazyString
java.lang.Object
org.eclipse.xtend.backend.common.EfficientLazyString
- All Implemented Interfaces:
- java.lang.CharSequence
public class EfficientLazyString
- extends java.lang.Object
- implements java.lang.CharSequence
This class is a "String" implementation that is optimized for efficient concatenation of arbitrary objects. It
has the specialty of converting its contents to Strings lazily, i.e. only when the toString method is called.
That allows slot-like behavior where an element that was added to the string can be modified later so that
the modified version actually gets into the resulting string.
Another specialty is that this class can stream its contents to a Writer without the necessity of creating an
intermediate string in memory.
One non-obvious benefit of consistent usage of this class is that mostly string constants from classes are stored
here, and they are "interned". This can significantly decrease memory footprint and improve performance.
- Author:
- Arno Haase (http://www.haase-consulting.com)
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
EfficientLazyString
public EfficientLazyString()
createAppendedString
public static EfficientLazyString createAppendedString(EfficientLazyString s,
java.lang.Object o)
makeImmutable
public void makeImmutable()
- makes this EfficientLazyString immutable, forcing concatenation to create a new EfficientLazyString instance. This
is done to comply with caching semantics, where the string value once returned from a function should not be
modified implicitly from outside that function.
writeTo
public void writeTo(java.io.Writer w)
throws java.io.IOException
- Throws:
java.io.IOException
toString
public java.lang.String toString()
- Specified by:
toString
in interface java.lang.CharSequence
- Overrides:
toString
in class java.lang.Object
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in class java.lang.Object
hashCode
public int hashCode()
- Overrides:
hashCode
in class java.lang.Object
charAt
public char charAt(int index)
- Specified by:
charAt
in interface java.lang.CharSequence
length
public int length()
- Specified by:
length
in interface java.lang.CharSequence
subSequence
public java.lang.CharSequence subSequence(int start,
int end)
- Specified by:
subSequence
in interface java.lang.CharSequence