<Swing Dev> Extension method for AbstractDocument.Content?

Pavel Porvatov pavel.porvatov at oracle.com
Thu Jun 21 13:13:30 UTC 2012


Hi Paulo,
> Hi. I've noticed that DefaultStyledDocument has a slowness issue when 
> inserting text. Even if you subclass it and expose the faster method:
> protected void insert(int offset, ElementSpec[] data)
>
> the body of the method still uses a stringbuilder to append all char[] 
> inside of the data before actually inserting into the content.
>
> This is because the only method for insertion in the default content 
> interface is:
> public UndoableEdit insertString(int where, String str)
>
> Now if there are going to be extension methods in java 8, it would be 
> nice to have a
> public UndoableEdit insert(int where, int index, int length, char[] 
> str) default {
>    return insert(where, new String(index, length, str);
> }
In which class do you suggest to add the new method?
>
> with a adequate specialization in GapContent (that obviously doesn't 
> call the string version), and that that new method is used in the
> protected void insert(int offset, ElementSpec[] data)
> method (and where it makes sense)
I'm not sure I understand correctly the last sentence. Could you please 
clarify that, please?

Thanks, Pavel



More information about the swing-dev mailing list