<Swing Dev> Extension method for AbstractDocument.Content?

Pavel Porvatov pavel.porvatov at oracle.com
Tue Jul 10 15:34:47 UTC 2012


Hi,
>
> Hi Paulo,
>
> On 6/21/2012 8:56 AM, Paulo Levi wrote:
>> 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)
>
>    Before fixing the performance issue it usually needs to have some 
> performance statistics, like:
>     - What is the difference between time execution or memory usage 
> for code with the fix and without the fix for text with different length
>     - Text with which length is commonly used in this method
>     - How often this method is used in real cases
>     - Is the most performance degradation is localized in this method 
> or may be where are other narrow places  which have performance issues 
> during a text manipulation
I agree with Alexander. Adding a new method in public API must be really 
reasonable. Otherwise we will get monstrous classes...

Regards, Pavel
>
>   Thanks,
>   Alexandr.
>
>
>
>>
>> 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);
>> }
>>
>> 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)
>
>




More information about the swing-dev mailing list