Details
-
Suggestion
-
Resolution: Done
-
P2: Important
-
4.2.0
-
None
-
c9607f069f0fb98021daf0af9f1d1b2981018e0c
Description
RC: ou1cimx1#421874
We had an exponential slowdown using QTextEdit with more than 2000 sentences. I used "AMD CodeAnalyst" and found that 80% of the processor time was spent in only 2 Qt methods! (Qt 4.1.3).
Probably the programmer knew there was something wrong because there is a comment in the code "#### binary search!"
So I did implement a non-recursive binary search and our problem was gone...
The two offending method were:
src/gui/text/qtextlayout.cpp QTextLine::layout_helper()
src/gui/text/qtextengine.cpp QTextEngine::findItem(int strPos) const
replace the "for" loop under the comment "#### binary search!" by this code:
------------------------------------------------------------
// #### binary search!
int item = -1;
int newItem;
/* old code
for (newItem = eng->layoutData->items.size()-1; newItem > 0;
--newItem)
*/
int left = 0;
int right = eng->layoutData->items.size()-1;
int middle;
int found = -1;
while(left <= right)
{
middle = ((int)((right-left)/2))+left;
if(line.from > eng->layoutData->items[middle].position)
left = middle+1;
else if(line.from < eng->layoutData->items[middle].position)
right = middle-1;
else
}
if(found != -1) newItem = found;
else newItem = right;
------------------------------------------------------------