Title: [148750] trunk/Source/WebCore
Revision
148750
Author
[email protected]
Date
2013-04-19 09:17:42 -0700 (Fri, 19 Apr 2013)

Log Message

[Mac] ComplexTextController is slow with large numbers of text runs.
<http://webkit.org/b/114875>
<rdar://problem/13337036>

Reviewed by Dan Bernstein.

Instead of iterating over the text runs in indexOfCurrentRun() to figure out the leftmost glyph,
create a lookup table of [run# -> distance in glyphs] at ComplexTextController construction time.

This avoids O(n^2) behavior in indexOfCurrentRun().

* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::ComplexTextController::ComplexTextController):
(WebCore::ComplexTextController::indexOfCurrentRun):
* platform/graphics/mac/ComplexTextController.h:
(ComplexTextController):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (148749 => 148750)


--- trunk/Source/WebCore/ChangeLog	2013-04-19 16:03:46 UTC (rev 148749)
+++ trunk/Source/WebCore/ChangeLog	2013-04-19 16:17:42 UTC (rev 148750)
@@ -1,3 +1,22 @@
+2013-04-19  Andreas Kling  <[email protected]>
+
+        [Mac] ComplexTextController is slow with large numbers of text runs.
+        <http://webkit.org/b/114875>
+        <rdar://problem/13337036>
+
+        Reviewed by Dan Bernstein.
+
+        Instead of iterating over the text runs in indexOfCurrentRun() to figure out the leftmost glyph,
+        create a lookup table of [run# -> distance in glyphs] at ComplexTextController construction time.
+
+        This avoids O(n^2) behavior in indexOfCurrentRun().
+
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::ComplexTextController::ComplexTextController):
+        (WebCore::ComplexTextController::indexOfCurrentRun):
+        * platform/graphics/mac/ComplexTextController.h:
+        (ComplexTextController):
+
 2013-04-19  Mario Sanchez Prada  <[email protected]>
 
         [GTK] Minimize calls to GailTextUtil in AtkText implementation

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp (148749 => 148750)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2013-04-19 16:03:46 UTC (rev 148749)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2013-04-19 16:17:42 UTC (rev 148750)
@@ -159,9 +159,17 @@
     collectComplexTextRuns();
     adjustGlyphsAndAdvances();
 
-    if (!m_isLTROnly)
+    if (!m_isLTROnly) {
         m_runIndices.reserveInitialCapacity(m_complexTextRuns.size());
 
+        m_glyphCountFromStartToIndex.reserveInitialCapacity(m_complexTextRuns.size());
+        unsigned glyphCountSoFar = 0;
+        for (unsigned i = 0; i < m_complexTextRuns.size(); ++i) {
+            m_glyphCountFromStartToIndex.uncheckedAppend(glyphCountSoFar);
+            glyphCountSoFar += m_complexTextRuns[i]->glyphCount();
+        }
+    }
+
     m_runWidthSoFar = m_leadingExpansion;
 }
 
@@ -448,8 +456,7 @@
     }
 
     unsigned currentRunIndex = m_runIndices[m_currentRun];
-    for (unsigned i = 0; i < currentRunIndex; ++i)
-        leftmostGlyph += m_complexTextRuns[i]->glyphCount();
+    leftmostGlyph = m_glyphCountFromStartToIndex[currentRunIndex];
     return currentRunIndex;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h (148749 => 148750)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h	2013-04-19 16:03:46 UTC (rev 148749)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h	2013-04-19 16:17:42 UTC (rev 148750)
@@ -132,9 +132,10 @@
     unsigned indexOfCurrentRun(unsigned& leftmostGlyph);
     unsigned incrementCurrentRun(unsigned& leftmostGlyph);
 
-    // The default size of this vector was selected as being the smallest power of two greater than
+    // The initial capacity of these vectors was selected as being the smallest power of two greater than
     // the average (3.5) plus one standard deviation (7.5) of nonzero sizes used on Arabic Wikipedia.
     Vector<unsigned, 16> m_runIndices;
+    Vector<unsigned, 16> m_glyphCountFromStartToIndex;
 
     const Font& m_font;
     const TextRun& m_run;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to