Changeset 148750 in webkit


Ignore:
Timestamp:
Apr 19, 2013 9:17:42 AM (11 years ago)
Author:
akling@apple.com
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(n2) behavior in indexOfCurrentRun().

  • platform/graphics/mac/ComplexTextController.cpp:

(WebCore::ComplexTextController::ComplexTextController):
(WebCore::ComplexTextController::indexOfCurrentRun):

  • platform/graphics/mac/ComplexTextController.h:

(ComplexTextController):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r148749 r148750  
     12013-04-19  Andreas Kling  <akling@apple.com>
     2
     3        [Mac] ComplexTextController is slow with large numbers of text runs.
     4        <http://webkit.org/b/114875>
     5        <rdar://problem/13337036>
     6
     7        Reviewed by Dan Bernstein.
     8
     9        Instead of iterating over the text runs in indexOfCurrentRun() to figure out the leftmost glyph,
     10        create a lookup table of [run# -> distance in glyphs] at ComplexTextController construction time.
     11
     12        This avoids O(n^2) behavior in indexOfCurrentRun().
     13
     14        * platform/graphics/mac/ComplexTextController.cpp:
     15        (WebCore::ComplexTextController::ComplexTextController):
     16        (WebCore::ComplexTextController::indexOfCurrentRun):
     17        * platform/graphics/mac/ComplexTextController.h:
     18        (ComplexTextController):
     19
    1202013-04-19  Mario Sanchez Prada  <mario.prada@samsung.com>
    221
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp

    r142206 r148750  
    160160    adjustGlyphsAndAdvances();
    161161
    162     if (!m_isLTROnly)
     162    if (!m_isLTROnly) {
    163163        m_runIndices.reserveInitialCapacity(m_complexTextRuns.size());
     164
     165        m_glyphCountFromStartToIndex.reserveInitialCapacity(m_complexTextRuns.size());
     166        unsigned glyphCountSoFar = 0;
     167        for (unsigned i = 0; i < m_complexTextRuns.size(); ++i) {
     168            m_glyphCountFromStartToIndex.uncheckedAppend(glyphCountSoFar);
     169            glyphCountSoFar += m_complexTextRuns[i]->glyphCount();
     170        }
     171    }
    164172
    165173    m_runWidthSoFar = m_leadingExpansion;
     
    449457
    450458    unsigned currentRunIndex = m_runIndices[m_currentRun];
    451     for (unsigned i = 0; i < currentRunIndex; ++i)
    452         leftmostGlyph += m_complexTextRuns[i]->glyphCount();
     459    leftmostGlyph = m_glyphCountFromStartToIndex[currentRunIndex];
    453460    return currentRunIndex;
    454461}
  • trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h

    r131703 r148750  
    133133    unsigned incrementCurrentRun(unsigned& leftmostGlyph);
    134134
    135     // The default size of this vector was selected as being the smallest power of two greater than
     135    // The initial capacity of these vectors was selected as being the smallest power of two greater than
    136136    // the average (3.5) plus one standard deviation (7.5) of nonzero sizes used on Arabic Wikipedia.
    137137    Vector<unsigned, 16> m_runIndices;
     138    Vector<unsigned, 16> m_glyphCountFromStartToIndex;
    138139
    139140    const Font& m_font;
Note: See TracChangeset for help on using the changeset viewer.