Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-231

Suggestion for significant speed improvement drawing text

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P2: Important
    • 4.7.0
    • 4.2.0
    • GUI: Text handling
    • 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)

      { if (eng->layoutData->items[newItem].position <= line.from) break; }

      */

      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

      { found = middle; // middle is exactly line.from break; }

      }
      if(found != -1) newItem = found;
      else newItem = right;
      ------------------------------------------------------------

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sletta Gunnar Sletta
            rve Anders Bakken
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes