summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2015-12-24 17:00:58 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-01-11 09:33:40 +0000
commit2ccacfb5c9a013fb8d32dfc90e55f0890e7b7a3a (patch)
treeafcc07195e41966f9eb22a7427b4f5f04fe7e6e5
parentb4c11c7cc56c18ebe14319b3389ff13c625e99d7 (diff)
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>
-rw-r--r--src/gui/text/qsyntaxhighlighter.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/gui/text/qsyntaxhighlighter.cpp b/src/gui/text/qsyntaxhighlighter.cpp
index f180a839b7..f300c18198 100644
--- a/src/gui/text/qsyntaxhighlighter.cpp
+++ b/src/gui/text/qsyntaxhighlighter.cpp
@@ -44,6 +44,8 @@
#include <qdebug.h>
#include <qtimer.h>
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
class QSyntaxHighlighterPrivate : public QObjectPrivate
@@ -96,15 +98,15 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
const int preeditAreaLength = layout->preeditAreaText().length();
if (preeditAreaLength != 0) {
- QVector<QTextLayout::FormatRange>::Iterator it = ranges.begin();
- while (it != ranges.end()) {
- if (it->start >= preeditAreaStart
- && it->start + it->length <= preeditAreaStart + preeditAreaLength) {
- ++it;
- } else {
- it = ranges.erase(it);
- formatsChanged = true;
- }
+ auto isOutsidePreeditArea = [=](const QTextLayout::FormatRange &range) {
+ return range.start < preeditAreaStart
+ || range.start + range.length > preeditAreaStart + preeditAreaLength;
+ };
+ const auto it = std::remove_if(ranges.begin(), ranges.end(),
+ isOutsidePreeditArea);
+ if (it != ranges.end()) {
+ ranges.erase(it, ranges.end());
+ formatsChanged = true;
}
} else if (!ranges.isEmpty()) {
ranges.clear();