Changeset 40471 in webkit
- Timestamp:
- Jan 31, 2009 10:23:39 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r40469 r40471 1 2009-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 1 25 2009-01-31 David Hyatt <hyatt@apple.com> 2 26 -
trunk/WebCore/rendering/RenderText.cpp
r40312 r40471 1015 1015 } 1016 1016 1017 unsigned int RenderText::width(unsigned int from, unsigned intlen, int xPos, bool firstLine) const1017 unsigned RenderText::width(unsigned from, unsigned len, int xPos, bool firstLine) const 1018 1018 { 1019 1019 if (from >= textLength()) … … 1026 1026 } 1027 1027 1028 unsigned int RenderText::width(unsigned int from, unsigned int len, const Font& f, int xPos) const 1029 { 1030 if (!characters() || from > textLength()) 1028 unsigned RenderText::width(unsigned from, unsigned len, const Font& f, int xPos) const 1029 { 1030 ASSERT(from + len <= textLength()); 1031 if (!characters()) 1031 1032 return 0; 1032 1033 if (from + len > textLength())1034 len = textLength() - from;1035 1033 1036 1034 int w; -
trunk/WebCore/rendering/bidi.cpp
r40411 r40471 1535 1535 } 1536 1536 1537 static 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 1537 1544 InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool firstLine, EClear* clear) 1538 1545 { … … 1743 1750 1744 1751 const Font& f = t->style(firstLine)->font(); 1752 bool isFixedPitch = f.isFixedPitch(); 1745 1753 1746 1754 int lastSpace = pos; … … 1791 1799 1792 1800 // 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; 1794 1802 1795 1803 // For wrapping text only, include the hyphen. We need to ensure it will fit 1796 1804 // on the line if it shows when we break. 1797 1805 if (autoWrap) 1798 tmpW += t ->width(pos, 1, f, w + tmpW);1806 tmpW += textWidth(t, pos, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace); 1799 1807 1800 1808 InlineIterator afterSoftHyphen(0, o, pos); … … 1816 1824 if ((breakAll || breakWords) && !midWordBreak) { 1817 1825 wrapW += charWidth; 1818 charWidth = t ->width(pos, 1, f, w + wrapW);1826 charWidth = textWidth(t, pos, 1, f, w + wrapW, isFixedPitch, collapseWhiteSpace); 1819 1827 midWordBreak = w + wrapW + charWidth > width; 1820 1828 } … … 1841 1849 } 1842 1850 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; 1844 1852 tmpW += additionalTmpW; 1845 1853 if (!appliedStartWidth) { … … 1858 1866 bool lineWasTooWide = false; 1859 1867 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); 1861 1869 // Check if line is too big even without the extra space 1862 1870 // at the end of the line. If it is not, do nothing. … … 1888 1896 if (pos > 0 && str[pos-1] == softHyphen) 1889 1897 // 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); 1891 1899 } 1892 1900 } … … 1979 1987 // IMPORTANT: pos is > length here! 1980 1988 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; 1982 1990 tmpW += inlineWidth(o, !appliedStartWidth, true); 1983 1991 } else
Note: See TracChangeset
for help on using the changeset viewer.