D12016: [ktexteditor] much faster positionFromCursor

Jaime Torres Amate noreply at phabricator.kde.org
Wed Apr 11 08:18:57 UTC 2018


jtamate updated this revision to Diff 31853.
jtamate marked 5 inline comments as done.
jtamate added a comment.


  Included more comments.
  Addressed style coding.
  
  In a callgrind log file with 1606189 lines, at the end of the file, pressing PageUp, using the code included at the end:
  
  old implementation elapsed =  122
  new implementation elapsed =  0
  old implementation elapsed =  119
  new implementation elapsed =  0
  
  After some insertions:
  old implementation elapsed =  137
  new implementation elapsed =  118
  old implementation elapsed =  123
  new implementation elapsed =  0
  
  - src/view/kateviewaccessible.h
  
  +++ src/view/kateviewaccessible.h
  @@ -29,6 +29,8 @@
   #include <QAccessible>
   #include <KLocalizedString>
   #include <QAccessibleWidget>
  +#include <QElapsedTimer>
  +#include <QDebug>
  
  /**
  
  - This class implements a QAccessible-interface for a KateViewInternal.
  
  @@ -194,6 +196,9 @@ public:
  
     */
    int positionFromCursor(KateViewInternal *view, const KTextEditor::Cursor &cursor) const
    {
  
  +        QElapsedTimer t;
  +        t.start();
  +
  
    int pos = m_lastPosition;
    const auto *doc = view->view()->document();
     
  
  @@ -229,6 +234,22 @@ public:
  
    m_lastCursor = cursor;
    m_lastPosition = pos;
     
  
  +        qWarning() << "new implementation elapsed = " << t.restart();
  +        // previous implementation
  +        int _pos = 0;
  +        for (int _line = 0; _line < cursor.line(); ++_line) {
  +            // length of the line plus newline
  +            _pos += view->view()->document()->line(_line).size() + 1;
  +        }
  +        _pos += cursor.column();
  +        qWarning() << "old implementation elapsed = " << t.elapsed();
  +
  +        return pos;
  +        if (_pos != (pos + cursor.column())) {
  +            qWarning() << "implementations differ, old=" << _pos << " new=" <<
  +pos + cursor.column();
  +        }
  +
  
        return pos + cursor.column();
    }

REPOSITORY
  R39 KTextEditor

CHANGES SINCE LAST UPDATE
  https://phabricator.kde.org/D12016?vs=31760&id=31853

REVISION DETAIL
  https://phabricator.kde.org/D12016

AFFECTED FILES
  src/view/kateviewaccessible.h
  src/view/kateviewinternal.cpp

To: jtamate, #kate, cullmann, #frameworks
Cc: mwolff, brauch, cullmann, #frameworks, michaelh, kevinapavew, ngraham, bruns, demsking, sars, dhaumann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20180411/daccc0e1/attachment-0001.html>


More information about the Kde-frameworks-devel mailing list