Changeset 127974 in webkit


Ignore:
Timestamp:
Sep 8, 2012 5:35:47 PM (12 years ago)
Author:
benjamin@webkit.org
Message:

Specialize nextBreakablePosition depending on breakNBSP
https://bugs.webkit.org/show_bug.cgi?id=96042

Patch by Benjamin Poulain <bpoulain@apple.com> on 2012-09-08
Reviewed by Eric Seidel.

The speed of isBreakableSpace() is limited by the speed of the inner loop of nextBreakablePosition().
The branches done to handle noBreakSpace can be simplified outside the loop
to reduce the number of tests inside the loop.

This patch split the code of nextBreakablePosition() in two function, depending if breakNBSP is true
or false.

If breakNBSP is true, isBreakableSpace() would return true on noBreakSpace.
->There is no need to test that value again for needsLineBreakIterator().
->There is no need to special case the switch() of isBreakableSpace() for noBreakSpace.

If breakNBSP is false:
->isBreakableSpace() does not need to test for noBreakSpace.

On x86_64, this improves PerformanceTests/Layout/line-layout.html by 2.8%.

  • rendering/break_lines.cpp:

(WebCore::isBreakableSpace):
(WebCore::nextBreakablePositionIgnoringNBSP):
(WebCore::nextBreakablePosition):

  • rendering/break_lines.h:

(WebCore::isBreakable): Remove the default value for breakNBSP, no caller is using it.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r127972 r127974  
     12012-09-08  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        Specialize nextBreakablePosition depending on breakNBSP
     4        https://bugs.webkit.org/show_bug.cgi?id=96042
     5
     6        Reviewed by Eric Seidel.
     7
     8        The speed of isBreakableSpace() is limited by the speed of the inner loop of nextBreakablePosition().
     9        The branches done to handle noBreakSpace can be simplified outside the loop
     10        to reduce the number of tests inside the loop.
     11
     12        This patch split the code of nextBreakablePosition() in two function, depending if breakNBSP is true
     13        or false.
     14
     15        If breakNBSP is true, isBreakableSpace() would return true on noBreakSpace.
     16        ->There is no need to test that value again for needsLineBreakIterator().
     17        ->There is no need to special case the switch() of isBreakableSpace() for noBreakSpace.
     18
     19        If breakNBSP is false:
     20        ->isBreakableSpace() does not need to test for noBreakSpace.
     21
     22        On x86_64, this improves PerformanceTests/Layout/line-layout.html by 2.8%.
     23
     24        * rendering/break_lines.cpp:
     25        (WebCore::isBreakableSpace):
     26        (WebCore::nextBreakablePositionIgnoringNBSP):
     27        (WebCore::nextBreakablePosition):
     28        * rendering/break_lines.h:
     29        (WebCore::isBreakable): Remove the default value for breakNBSP, no caller is using it.
     30
    1312012-09-08  Adam Barth  <abarth@chromium.org>
    232
  • trunk/Source/WebCore/rendering/break_lines.cpp

    r120624 r127974  
    3939namespace WebCore {
    4040
    41 static inline bool isBreakableSpace(UChar ch, bool treatNoBreakSpaceAsBreak)
     41template<bool treatNoBreakSpaceAsBreak>
     42static inline bool isBreakableSpace(UChar ch)
    4243{
    4344    switch (ch) {
     
    139140}
    140141
    141 static inline bool needsLineBreakIterator(UChar ch)
     142template<bool treatNoBreakSpaceAsBreak>
     143inline bool needsLineBreakIterator(UChar ch)
    142144{
     145    if (treatNoBreakSpaceAsBreak)
     146        return ch > asciiLineBreakTableLastChar;
    143147    return ch > asciiLineBreakTableLastChar && ch != noBreakSpace;
    144148}
    145149
    146 int nextBreakablePosition(LazyLineBreakIterator& lazyBreakIterator, int pos, bool treatNoBreakSpaceAsBreak)
     150template<bool treatNoBreakSpaceAsBreak>
     151static inline int nextBreakablePosition(LazyLineBreakIterator& lazyBreakIterator, int pos)
    147152{
    148153    const UChar* str = lazyBreakIterator.string();
     
    155160        UChar ch = str[i];
    156161
    157         if (isBreakableSpace(ch, treatNoBreakSpaceAsBreak) || shouldBreakAfter(lastLastCh, lastCh, ch))
     162        if (isBreakableSpace<treatNoBreakSpaceAsBreak>(ch) || shouldBreakAfter(lastLastCh, lastCh, ch))
    158163            return i;
    159164
    160         if (needsLineBreakIterator(ch) || needsLineBreakIterator(lastCh)) {
     165        if (needsLineBreakIterator<treatNoBreakSpaceAsBreak>(ch) || needsLineBreakIterator<treatNoBreakSpaceAsBreak>(lastCh)) {
    161166            if (nextBreak < i && i) {
    162167                TextBreakIterator* breakIterator = lazyBreakIterator.get();
     
    164169                    nextBreak = textBreakFollowing(breakIterator, i - 1);
    165170            }
    166             if (i == nextBreak && !isBreakableSpace(lastCh, treatNoBreakSpaceAsBreak))
     171            if (i == nextBreak && !isBreakableSpace<treatNoBreakSpaceAsBreak>(lastCh))
    167172                return i;
    168173        }
     
    175180}
    176181
     182int nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator& lazyBreakIterator, int pos)
     183{
     184    return nextBreakablePosition<false>(lazyBreakIterator, pos);
     185}
     186
     187int nextBreakablePosition(LazyLineBreakIterator& lazyBreakIterator, int pos)
     188{
     189    return nextBreakablePosition<true>(lazyBreakIterator, pos);
     190}
     191
    177192} // namespace WebCore
  • trunk/Source/WebCore/rendering/break_lines.h

    r79694 r127974  
    2828class LazyLineBreakIterator;
    2929
    30 int nextBreakablePosition(LazyLineBreakIterator&, int pos, bool breakNBSP = false);
     30int nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator&, int pos);
     31int nextBreakablePosition(LazyLineBreakIterator&, int pos);
    3132
    32 inline bool isBreakable(LazyLineBreakIterator& lazyBreakIterator, int pos, int& nextBreakable, bool breakNBSP = false)
     33inline bool isBreakable(LazyLineBreakIterator& lazyBreakIterator, int pos, int& nextBreakable, bool breakNBSP)
    3334{
    34     if (pos > nextBreakable)
    35         nextBreakable = nextBreakablePosition(lazyBreakIterator, pos, breakNBSP);
     35    if (pos > nextBreakable) {
     36        if (breakNBSP)
     37            nextBreakable = nextBreakablePosition(lazyBreakIterator, pos);
     38        else
     39            nextBreakable = nextBreakablePositionIgnoringNBSP(lazyBreakIterator, pos);
     40    }
    3641    return pos == nextBreakable;
    3742}
Note: See TracChangeset for help on using the changeset viewer.