From: <k_s...@us...> - 2012-02-23 16:36:36
|
Revision: 21190 http://jedit.svn.sourceforge.net/jedit/?rev=21190&view=rev Author: k_satoda Date: 2012-02-23 16:36:27 +0000 (Thu, 23 Feb 2012) Log Message: ----------- Eliminated quadratic iteration in DisplayTokenHandler.recalculateTabWidth() which could choke CPU when wrapping very long lines. If a line consists of 1000 chunks and the line is wrapped at every second chunk, the iteration goes roughly 998 + 996 + ... + 2 = 249500 times. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java Modified: jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-23 09:32:46 UTC (rev 21189) +++ jEdit/trunk/org/gjt/sp/jedit/syntax/DisplayTokenHandler.java 2012-02-23 16:36:27 UTC (rev 21190) @@ -244,7 +244,9 @@ } //}}} //{{{ recalculateTabWidth() method - private float recalculateTabWidth(Chunk lineHead, Segment lineText) + // Returns true if all chunks are recaluculated and the total + // width fits in wrap margin. + private boolean recalculateTabWidthInWrapMargin(Chunk lineHead, Segment lineText) { float x = 0.0f; for(Chunk chunk = lineHead; chunk != null; chunk = (Chunk)chunk.next) @@ -254,8 +256,12 @@ initChunk(chunk, x, lineText); } x += chunk.width; + if(x > wrapMargin) + { + return false; + } } - return x; + return true; } //}}} //{{{ countLeadingWhitespaces() method @@ -362,7 +368,7 @@ lineHead = remaining; } lineHead = makeWrappedLine(lineHead, virtualIndentWidth, lineText); - if(recalculateTabWidth(lineHead, lineText) <= wrapMargin) + if(recalculateTabWidthInWrapMargin(lineHead, lineText)) { // Fits in the margin. No more need to wrap. out.add(lineHead); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |