Changeset 40471 in webkit


Ignore:
Timestamp:
Jan 31, 2009 10:23:39 PM (15 years ago)
Author:
mitz@apple.com
Message:

Reviewed by Oliver Hunt.

  • fix <rdar://problem/6546549> Eliminate some RenderText::width() overhead from findNextLineBreak()

On the PLT, this results in 0.36x the number of virtual function calls
to RenderText::width() and 0.69x the number of calls to
Font::isFixedPitch(), but makes 1.0004x the number of calls to
Font::width().

  • rendering/RenderText.cpp: (WebCore::RenderText::width): Replaced bounds checks on 'from' and 'len' with an assertion.
  • rendering/bidi.cpp: (WebCore::textWidth): Added this inlined helper function which calls Font::width() directly in the non-fixed-pitch, non-full-range case, and otherwise calls RenderText::width(). (WebCore::RenderBlock::findNextLineBreak): Cache whether the font has fixed pitch (in which case RenderText::width() will be called in order to take advantage of the widthFromCache() optimization for fixed-pitch fonts). Replaced all calls to RenderText::width() with calls to the textWidth() helper function.
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r40469 r40471  
     12009-01-31  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        - fix <rdar://problem/6546549> Eliminate some RenderText::width() overhead from findNextLineBreak()
     6
     7        On the PLT, this results in 0.36x the number of virtual function calls
     8        to RenderText::width() and 0.69x the number of calls to
     9        Font::isFixedPitch(), but makes 1.0004x the number of calls to
     10        Font::width().
     11
     12        * rendering/RenderText.cpp:
     13        (WebCore::RenderText::width): Replaced bounds checks on 'from' and 'len'
     14        with an assertion.
     15        * rendering/bidi.cpp:
     16        (WebCore::textWidth): Added this inlined helper function which calls
     17        Font::width() directly in the non-fixed-pitch, non-full-range case, and
     18        otherwise calls RenderText::width().
     19        (WebCore::RenderBlock::findNextLineBreak): Cache whether the font has
     20        fixed pitch (in which case RenderText::width() will be called in order
     21        to take advantage of the widthFromCache() optimization for fixed-pitch
     22        fonts). Replaced all calls to RenderText::width() with calls to the
     23        textWidth() helper function.
     24
    1252009-01-31  David Hyatt  <hyatt@apple.com>
    226
  • trunk/WebCore/rendering/RenderText.cpp

    r40312 r40471  
    10151015}
    10161016
    1017 unsigned int RenderText::width(unsigned int from, unsigned int len, int xPos, bool firstLine) const
     1017unsigned RenderText::width(unsigned from, unsigned len, int xPos, bool firstLine) const
    10181018{
    10191019    if (from >= textLength())
     
    10261026}
    10271027
    1028 unsigned int RenderText::width(unsigned int from, unsigned int len, const Font& f, int xPos) const
    1029 {
    1030     if (!characters() || from > textLength())
     1028unsigned RenderText::width(unsigned from, unsigned len, const Font& f, int xPos) const
     1029{
     1030    ASSERT(from + len <= textLength());
     1031    if (!characters())
    10311032        return 0;
    1032 
    1033     if (from + len > textLength())
    1034         len = textLength() - from;
    10351033
    10361034    int w;
  • trunk/WebCore/rendering/bidi.cpp

    r40411 r40471  
    15351535}
    15361536
     1537static inline unsigned textWidth(RenderText* text, unsigned from, unsigned len, const Font& font, int xPos, bool isFixedPitch, bool collapseWhiteSpace)
     1538{
     1539    if (isFixedPitch || !from && len == text->textLength())
     1540        return text->width(from, len, font, xPos);
     1541    return font.width(TextRun(text->characters() + from, len, !collapseWhiteSpace, xPos));
     1542}
     1543
    15371544InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool firstLine, EClear* clear)
    15381545{
     
    17431750
    17441751            const Font& f = t->style(firstLine)->font();
     1752            bool isFixedPitch = f.isFixedPitch();
    17451753
    17461754            int lastSpace = pos;
     
    17911799
    17921800                        // Add the width up to but not including the hyphen.
    1793                         tmpW += t->width(lastSpace, pos - lastSpace, f, w + tmpW) + lastSpaceWordSpacing;
     1801                        tmpW += textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
    17941802
    17951803                        // For wrapping text only, include the hyphen.  We need to ensure it will fit
    17961804                        // on the line if it shows when we break.
    17971805                        if (autoWrap)
    1798                             tmpW += t->width(pos, 1, f, w + tmpW);
     1806                            tmpW += textWidth(t, pos, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace);
    17991807
    18001808                        InlineIterator afterSoftHyphen(0, o, pos);
     
    18161824                if ((breakAll || breakWords) && !midWordBreak) {
    18171825                    wrapW += charWidth;
    1818                     charWidth = t->width(pos, 1, f, w + wrapW);
     1826                    charWidth = textWidth(t, pos, 1, f, w + wrapW, isFixedPitch, collapseWhiteSpace);
    18191827                    midWordBreak = w + wrapW + charWidth > width;
    18201828                }
     
    18411849                    }
    18421850
    1843                     int additionalTmpW = t->width(lastSpace, pos - lastSpace, f, w+tmpW) + lastSpaceWordSpacing;
     1851                    int additionalTmpW = textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
    18441852                    tmpW += additionalTmpW;
    18451853                    if (!appliedStartWidth) {
     
    18581866                        bool lineWasTooWide = false;
    18591867                        if (w + tmpW <= width && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) {
    1860                             int charWidth = t->width(pos, 1, f, w + tmpW) + (applyWordSpacing ? wordSpacing : 0);
     1868                            int charWidth = textWidth(t, pos, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + (applyWordSpacing ? wordSpacing : 0);
    18611869                            // Check if line is too big even without the extra space
    18621870                            // at the end of the line. If it is not, do nothing.
     
    18881896                            if (pos > 0 && str[pos-1] == softHyphen)
    18891897                                // Subtract the width of the soft hyphen out since we fit on a line.
    1890                                 tmpW -= t->width(pos-1, 1, f, w+tmpW);
     1898                                tmpW -= textWidth(t, pos - 1, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace);
    18911899                        }
    18921900                    }
     
    19791987            // IMPORTANT: pos is > length here!
    19801988            if (!ignoringSpaces)
    1981                 tmpW += t->width(lastSpace, pos - lastSpace, f, w+tmpW) + lastSpaceWordSpacing;
     1989                tmpW += textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
    19821990            tmpW += inlineWidth(o, !appliedStartWidth, true);
    19831991        } else
Note: See TracChangeset for help on using the changeset viewer.