Title: [127974] trunk/Source/WebCore
Revision
127974
Author
[email protected]
Date
2012-09-08 17:35:47 -0700 (Sat, 08 Sep 2012)

Log Message

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

Patch by Benjamin Poulain <[email protected]> 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (127973 => 127974)


--- trunk/Source/WebCore/ChangeLog	2012-09-08 19:50:03 UTC (rev 127973)
+++ trunk/Source/WebCore/ChangeLog	2012-09-09 00:35:47 UTC (rev 127974)
@@ -1,3 +1,33 @@
+2012-09-08  Benjamin Poulain  <[email protected]>
+
+        Specialize nextBreakablePosition depending on breakNBSP
+        https://bugs.webkit.org/show_bug.cgi?id=96042
+
+        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.
+
 2012-09-08  Adam Barth  <[email protected]>
 
         [V8] DOM wrapper creation involves a bunch of sketchy code related to finding the Frame

Modified: trunk/Source/WebCore/rendering/break_lines.cpp (127973 => 127974)


--- trunk/Source/WebCore/rendering/break_lines.cpp	2012-09-08 19:50:03 UTC (rev 127973)
+++ trunk/Source/WebCore/rendering/break_lines.cpp	2012-09-09 00:35:47 UTC (rev 127974)
@@ -38,7 +38,8 @@
 
 namespace WebCore {
 
-static inline bool isBreakableSpace(UChar ch, bool treatNoBreakSpaceAsBreak)
+template<bool treatNoBreakSpaceAsBreak>
+static inline bool isBreakableSpace(UChar ch)
 {
     switch (ch) {
     case ' ':
@@ -138,12 +139,16 @@
     return false;
 }
 
-static inline bool needsLineBreakIterator(UChar ch)
+template<bool treatNoBreakSpaceAsBreak>
+inline bool needsLineBreakIterator(UChar ch)
 {
+    if (treatNoBreakSpaceAsBreak)
+        return ch > asciiLineBreakTableLastChar;
     return ch > asciiLineBreakTableLastChar && ch != noBreakSpace;
 }
 
-int nextBreakablePosition(LazyLineBreakIterator& lazyBreakIterator, int pos, bool treatNoBreakSpaceAsBreak)
+template<bool treatNoBreakSpaceAsBreak>
+static inline int nextBreakablePosition(LazyLineBreakIterator& lazyBreakIterator, int pos)
 {
     const UChar* str = lazyBreakIterator.string();
     int len = lazyBreakIterator.length();
@@ -154,16 +159,16 @@
     for (int i = pos; i < len; i++) {
         UChar ch = str[i];
 
-        if (isBreakableSpace(ch, treatNoBreakSpaceAsBreak) || shouldBreakAfter(lastLastCh, lastCh, ch))
+        if (isBreakableSpace<treatNoBreakSpaceAsBreak>(ch) || shouldBreakAfter(lastLastCh, lastCh, ch))
             return i;
 
-        if (needsLineBreakIterator(ch) || needsLineBreakIterator(lastCh)) {
+        if (needsLineBreakIterator<treatNoBreakSpaceAsBreak>(ch) || needsLineBreakIterator<treatNoBreakSpaceAsBreak>(lastCh)) {
             if (nextBreak < i && i) {
                 TextBreakIterator* breakIterator = lazyBreakIterator.get();
                 if (breakIterator)
                     nextBreak = textBreakFollowing(breakIterator, i - 1);
             }
-            if (i == nextBreak && !isBreakableSpace(lastCh, treatNoBreakSpaceAsBreak))
+            if (i == nextBreak && !isBreakableSpace<treatNoBreakSpaceAsBreak>(lastCh))
                 return i;
         }
 
@@ -174,4 +179,14 @@
     return len;
 }
 
+int nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator& lazyBreakIterator, int pos)
+{
+    return nextBreakablePosition<false>(lazyBreakIterator, pos);
+}
+
+int nextBreakablePosition(LazyLineBreakIterator& lazyBreakIterator, int pos)
+{
+    return nextBreakablePosition<true>(lazyBreakIterator, pos);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/break_lines.h (127973 => 127974)


--- trunk/Source/WebCore/rendering/break_lines.h	2012-09-08 19:50:03 UTC (rev 127973)
+++ trunk/Source/WebCore/rendering/break_lines.h	2012-09-09 00:35:47 UTC (rev 127974)
@@ -27,12 +27,17 @@
 
 class LazyLineBreakIterator;
 
-int nextBreakablePosition(LazyLineBreakIterator&, int pos, bool breakNBSP = false);
+int nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator&, int pos);
+int nextBreakablePosition(LazyLineBreakIterator&, int pos);
 
-inline bool isBreakable(LazyLineBreakIterator& lazyBreakIterator, int pos, int& nextBreakable, bool breakNBSP = false)
+inline bool isBreakable(LazyLineBreakIterator& lazyBreakIterator, int pos, int& nextBreakable, bool breakNBSP)
 {
-    if (pos > nextBreakable)
-        nextBreakable = nextBreakablePosition(lazyBreakIterator, pos, breakNBSP);
+    if (pos > nextBreakable) {
+        if (breakNBSP)
+            nextBreakable = nextBreakablePosition(lazyBreakIterator, pos);
+        else
+            nextBreakable = nextBreakablePositionIgnoringNBSP(lazyBreakIterator, pos);
+    }
     return pos == nextBreakable;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to