Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 340317

Summary: TextUtils.getShortString() is slow for longer texts
Product: z_Archived Reporter: Markus Barchfeld <Markus.Barchfeld>
Component: NebulaAssignee: Thomas Schindl <tom.schindl>
Status: CLOSED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: caosmpz, cgross
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch for Text Util none

Description Markus Barchfeld CLA 2011-03-17 10:12:02 EDT
Build Identifier: 3.5.2

TextUtils.getShortString() is used from the DefaultCellRenderer to abbreviate texts if the grid is not word wrapping. For particular strings  with a length of about 2000 characters this method can consume up to 600ms on my Core duo 2.5 GHZ.

The algorithm splits the string and then decreases it by one until it fits into the width of the column. For every turn it calls GC.textExtent twice. Assuming that the text width is an ordered function over the character size the algorithm could use a binary search and thereby reduce the number of calls from n to log n. 

Attached is a patch with the modified algorithm and test cases for checking the compatibility with the existing implementation. It reduces the time to about 15ms for the example (which is also part of the test case).


Reproducible: Always
Comment 1 Markus Barchfeld CLA 2011-03-17 10:12:46 EDT
Created attachment 191419 [details]
Patch for Text Util
Comment 2 Mirko Paturzo CLA 2016-01-22 02:44:11 EST

*** This bug has been marked as a duplicate of bug 440812 ***