core-libs-dev Digest, Vol 7, Issue 8
Paulo Levi
i30817 at gmail.com
Sat Nov 24 23:18:19 UTC 2007
Could you look in fixing the insertString(int where, String str) or
was it replace(int position, String str, int addsize), method in
GapContent ?
Currently it makes a totally unneeded copy that stresses the garbage
collector where it could use something like this (i removed the
undoableEdit on purpose)
public UndoableEdit insertString(int where, String str) throws
BadLocationException {
if (where > length() || where < 0) {
throw new BadLocationException("Invalid insert", length());
}
//char [] s = str.toCharArray();
//replace(where, 0, s, s.length);
replace(where, str, str.length());
return null;
}
protected void replace(int position, String addItems, int addSize) {
if (addSize == 0) {
return;
} else {
int end = open(position, addSize);
//System.arraycopy(addItems, rmSize, array, end, endSize);
addItems.getChars(0, addSize, (char[]) getArray(), end);
}
}
Another thing:
the default smallattributeset created in the DefaultStyledDocument
takes far to much time to be found in a hashmap (where it lives) i
added a small check for the degenerate case where the attribute count
is equal to 0 to not have to enter containsattributes. In my
application this was a hotstop, i don't remember exactly where (
I think it was setCharacterAttributes of DefaultStyledDocument, that
caused in turn an addEdit to a DefaultDocumentEvent that used a
hashmap, and that edit would be got later).
protected SmallAttributeSet createSmallAttributeSet(AttributeSet a) {
return new SmallAttributeSet(a){
//hashcode of superclass. Redefined to see if
weakhasmap behaves better
@Override
public boolean equals(Object obj){
if (obj instanceof AttributeSet) {
AttributeSet attrs = (AttributeSet) obj;
return getAttributeCount() == attrs.getAttributeCount()
&& (getAttributeCount() == 0 ||
containsAttributes(attrs));
}
return false;
}
};
}
More information about the core-libs-dev
mailing list