Commit 2ccacfb5 authored by Anton Kudryavtsev's avatar Anton Kudryavtsev
Browse files

QSyntaxHighlighterPrivate: use erase and std::remove_if with QVector


... instead of using erase in a loop, with quadratic complexity.

Change-Id: If30c6c99a775aec07eef9ddf953e944dc916b5a2
Reviewed-by: default avatarLars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: default avatarMarc Mutz <marc.mutz@kdab.com>
parent b4c11c7c
Branches
Tags
No related merge requests found
Showing with 11 additions and 9 deletions
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include <qdebug.h> #include <qdebug.h>
#include <qtimer.h> #include <qtimer.h>
#include <algorithm>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QSyntaxHighlighterPrivate : public QObjectPrivate class QSyntaxHighlighterPrivate : public QObjectPrivate
...@@ -96,15 +98,15 @@ void QSyntaxHighlighterPrivate::applyFormatChanges() ...@@ -96,15 +98,15 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
const int preeditAreaLength = layout->preeditAreaText().length(); const int preeditAreaLength = layout->preeditAreaText().length();
if (preeditAreaLength != 0) { if (preeditAreaLength != 0) {
QVector<QTextLayout::FormatRange>::Iterator it = ranges.begin(); auto isOutsidePreeditArea = [=](const QTextLayout::FormatRange &range) {
while (it != ranges.end()) { return range.start < preeditAreaStart
if (it->start >= preeditAreaStart || range.start + range.length > preeditAreaStart + preeditAreaLength;
&& it->start + it->length <= preeditAreaStart + preeditAreaLength) { };
++it; const auto it = std::remove_if(ranges.begin(), ranges.end(),
} else { isOutsidePreeditArea);
it = ranges.erase(it); if (it != ranges.end()) {
formatsChanged = true; ranges.erase(it, ranges.end());
} formatsChanged = true;
} }
} else if (!ranges.isEmpty()) { } else if (!ranges.isEmpty()) {
ranges.clear(); ranges.clear();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment