diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-07-06 10:20:24 (GMT) |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-07-06 10:20:24 (GMT) |
commit | f62f6effab8d1551d8e5e5843dc478addee96de1 (patch) | |
tree | 1d47256a1ad69d967b2c4227dfdd15207d195cf0 /src/gui/text/qtextdocument_p.cpp | |
parent | 7e35c6ff442e237ff9a1bec9ea1cdfb597d9ceae (diff) | |
download | Qt-f62f6effab8d1551d8e5e5843dc478addee96de1.zip Qt-f62f6effab8d1551d8e5e5843dc478addee96de1.tar.gz Qt-f62f6effab8d1551d8e5e5843dc478addee96de1.tar.bz2 |
Fix performance of QTextDocumentPrivate::adjustDocumentChangesAndCursors
As the changedCursors list grew large, the function used to spend an
extraordinate amount of time in QList::contains.
The fix removes the changedCursors list outright and replaces it with a
flag in QTextCursorPrivate.
Done-with: mae
Diffstat (limited to 'src/gui/text/qtextdocument_p.cpp')
-rw-r--r-- | src/gui/text/qtextdocument_p.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index a55e5f3..9849317 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -235,17 +235,17 @@ void QTextDocumentPrivate::init() void QTextDocumentPrivate::clear() { Q_Q(QTextDocument); - for (int i = 0; i < cursors.count(); ++i) { - cursors.at(i)->setPosition(0); - cursors.at(i)->currentCharFormat = -1; - cursors.at(i)->anchor = 0; - cursors.at(i)->adjusted_anchor = 0; + + foreach (QTextCursorPrivate *curs, cursors) { + curs->setPosition(0); + curs->currentCharFormat = -1; + curs->anchor = 0; + curs->adjusted_anchor = 0; } QList<QTextCursorPrivate *>oldCursors = cursors; QT_TRY{ cursors.clear(); - changedCursors.clear(); QMap<int, QTextObject *>::Iterator objectIt = objects.begin(); while (objectIt != objects.end()) { @@ -288,8 +288,8 @@ void QTextDocumentPrivate::clear() QTextDocumentPrivate::~QTextDocumentPrivate() { - for (int i = 0; i < cursors.count(); ++i) - cursors.at(i)->priv = 0; + foreach (QTextCursorPrivate *curs, cursors) + curs->priv = 0; cursors.clear(); undoState = 0; undoEnabled = true; @@ -1225,9 +1225,11 @@ void QTextDocumentPrivate::finishEdit() } } - while (!changedCursors.isEmpty()) { - QTextCursorPrivate *curs = changedCursors.takeFirst(); - emit q->cursorPositionChanged(QTextCursor(curs)); + foreach (QTextCursorPrivate *curs, cursors) { + if (curs->changed) { + curs->changed = false; + emit q->cursorPositionChanged(QTextCursor(curs)); + } } contentsChanged(); @@ -1273,11 +1275,9 @@ void QTextDocumentPrivate::adjustDocumentChangesAndCursors(int from, int addedOr if (!editBlock) ++revision; - for (int i = 0; i < cursors.size(); ++i) { - QTextCursorPrivate *curs = cursors.at(i); + foreach (QTextCursorPrivate *curs, cursors) { if (curs->adjustPosition(from, addedOrRemoved, op) == QTextCursorPrivate::CursorMoved) { - if (!changedCursors.contains(curs)) - changedCursors.append(curs); + curs->changed = true; } } @@ -1700,8 +1700,8 @@ bool QTextDocumentPrivate::ensureMaximumBlockCount() void QTextDocumentPrivate::aboutToRemoveCell(int from, int to) { Q_ASSERT(from <= to); - for (int i = 0; i < cursors.size(); ++i) - cursors.at(i)->aboutToRemoveCell(from, to); + foreach (QTextCursorPrivate *curs, cursors) + curs->aboutToRemoveCell(from, to); } QT_END_NAMESPACE |