QSyntaxHighlighter: minor code de-duplication
authorKonstantin Ritt <ritt.ks@gmail.com>
Sat, 27 Oct 2012 06:11:36 +0000 (09:11 +0300)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 29 Oct 2012 21:21:32 +0000 (22:21 +0100)
The (r.start != -1) case is equal to (i == formatChanges.count()) case
in the loop; no need to exit the loop just to do exactly what it did.

Change-Id: I4129d8012399895c2fce70b26716ca5aeadee79c
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
src/gui/text/qsyntaxhighlighter.cpp

index 7baf55c..f183e1e 100644 (file)
@@ -119,18 +119,14 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
         formatsChanged = true;
     }
 
-    QTextCharFormat emptyFormat;
-
-    QTextLayout::FormatRange r;
-    r.start = -1;
-
     int i = 0;
     while (i < formatChanges.count()) {
+        QTextLayout::FormatRange r;
 
-        while (i < formatChanges.count() && formatChanges.at(i) == emptyFormat)
+        while (i < formatChanges.count() && formatChanges.at(i) == r.format)
             ++i;
 
-        if (i >= formatChanges.count())
+        if (i == formatChanges.count())
             break;
 
         r.start = i;
@@ -139,9 +135,7 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
         while (i < formatChanges.count() && formatChanges.at(i) == r.format)
             ++i;
 
-        if (i >= formatChanges.count())
-            break;
-
+        Q_ASSERT(i <= formatChanges.count());
         r.length = i - r.start;
 
         if (preeditAreaLength != 0) {
@@ -153,21 +147,6 @@ void QSyntaxHighlighterPrivate::applyFormatChanges()
 
         ranges << r;
         formatsChanged = true;
-        r.start = -1;
-    }
-
-    if (r.start != -1) {
-        r.length = formatChanges.count() - r.start;
-
-        if (preeditAreaLength != 0) {
-            if (r.start >= preeditAreaStart)
-                r.start += preeditAreaLength;
-            else if (r.start + r.length >= preeditAreaStart)
-                r.length += preeditAreaLength;
-        }
-
-        ranges << r;
-        formatsChanged = true;
     }
 
     if (formatsChanged) {