2011-03-29 Eric Seidel <eric@webkit.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Mar 2011 04:55:31 +0000 (04:55 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Mar 2011 04:55:31 +0000 (04:55 +0000)
        Reviewed by Ryosuke Niwa.

        Split more logic out from createBidiRunsForLine for readability
        https://bugs.webkit.org/show_bug.cgi?id=57341

        I marked reorderRunsFromLevels inline, but it probably doesn't actually need to (or want to) be.
        This lops another large hunk off of reorderRunsFromLevels further reducing the size and complexity.

        * platform/text/BidiResolver.h:
        (WebCore::::reorderRunsFromLevels):
        (WebCore::::createBidiRunsForLine):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@82389 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/text/BidiResolver.h

index 9c208da098f9beac2e249d8c421f3975f723434d..94c8aa0bd73c8c6122d20ba16eb327c956a3c5fb 100644 (file)
@@ -1,3 +1,17 @@
+2011-03-29  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by Ryosuke Niwa.
+
+        Split more logic out from createBidiRunsForLine for readability
+        https://bugs.webkit.org/show_bug.cgi?id=57341
+
+        I marked reorderRunsFromLevels inline, but it probably doesn't actually need to (or want to) be.
+        This lops another large hunk off of reorderRunsFromLevels further reducing the size and complexity.
+
+        * platform/text/BidiResolver.h:
+        (WebCore::::reorderRunsFromLevels):
+        (WebCore::::createBidiRunsForLine):
+
 2011-03-29  Kent Tamura  <tkent@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index a884bf7ef84923d93c5698eac368cc556a7f9e20..b81d19d5d08b83ef8d7ad7462788a3c5102fb8cf 100644 (file)
@@ -211,6 +211,7 @@ private:
     void checkDirectionInLowerRaiseEmbeddingLevel();
 
     void updateStatusLastFromCurrentDirection(WTF::Unicode::Direction);
+    void reorderRunsFromLevels();
 
     Vector<WTF::Unicode::Direction, 8> m_currentExplicitEmbeddingSequence;
 };
@@ -563,6 +564,43 @@ inline void BidiResolver<Iterator, Run>::updateStatusLastFromCurrentDirection(WT
     }
 }
 
+template <class Iterator, class Run>
+inline void BidiResolver<Iterator, Run>::reorderRunsFromLevels()
+{
+    unsigned char levelLow = 128;
+    unsigned char levelHigh = 0;
+    for (Run* run = firstRun(); run; run = run->next()) {
+        levelHigh = std::max(run->level(), levelHigh);
+        levelLow = std::min(run->level(), levelLow);
+    }
+
+    // This implements reordering of the line (L2 according to Bidi spec):
+    // http://unicode.org/reports/tr9/#L2
+    // L2. From the highest level found in the text to the lowest odd level on each line,
+    // reverse any contiguous sequence of characters that are at that level or higher.
+
+    // Reversing is only done up to the lowest odd level.
+    if (!(levelLow % 2))
+        levelLow++;
+
+    unsigned count = runCount() - 1;
+
+    while (levelHigh >= levelLow) {
+        unsigned i = 0;
+        Run* run = firstRun();
+        while (i < count) {
+            for (;i < count && run && run->level() < levelHigh; i++)
+                run = run->next();
+            unsigned start = i;
+            for (;i <= count && run && run->level() >= levelHigh; i++)
+                run = run->next();
+            unsigned end = i - 1;
+            reverseRuns(start, end);
+        }
+        levelHigh--;
+    }
+}
+
 template <class Iterator, class Run>
 void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, VisualDirectionOverride override, bool hardLineBreak)
 {
@@ -943,44 +981,7 @@ void BidiResolver<Iterator, Run>::createBidiRunsForLine(const Iterator& end, Vis
     }
 
     m_logicallyLastRun = m_lastRun;
-
-    // reorder line according to run structure...
-    // first find highest and lowest levels
-    unsigned char levelLow = 128;
-    unsigned char levelHigh = 0;
-    for (Run* r = firstRun(); r; r = r->next()) {
-        levelHigh = std::max(r->m_level, levelHigh);
-        levelLow = std::min(r->m_level, levelLow);
-    }
-
-    // implements reordering of the line (L2 according to Bidi spec):
-    // L2. From the highest level found in the text to the lowest odd level on each line,
-    // reverse any contiguous sequence of characters that are at that level or higher.
-
-    // reversing is only done up to the lowest odd level
-    if (!(levelLow % 2))
-        levelLow++;
-
-    unsigned count = runCount() - 1;
-
-    while (levelHigh >= levelLow) {
-        unsigned i = 0;
-        Run* currRun = firstRun();
-        while (i < count) {
-            while (i < count && currRun && currRun->m_level < levelHigh) {
-                i++;
-                currRun = currRun->next();
-            }
-            unsigned start = i;
-            while (i <= count && currRun && currRun->m_level >= levelHigh) {
-                i++;
-                currRun = currRun->next();
-            }
-            unsigned end = i - 1;
-            reverseRuns(start, end);
-        }
-        levelHigh--;
-    }
+    reorderRunsFromLevels();
     endOfLine = Iterator();
 }