QSyntaxHighlighterPrivate: use erase and std::remove_if with QVector
... instead of using erase in a loop, with quadratic complexity. Change-Id: If30c6c99a775aec07eef9ddf953e944dc916b5a2 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
b4c11c7cc5
commit
2ccacfb5c9
@ -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()
|
|||||||
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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user