Title: [254630] trunk/Source/WebCore
Revision
254630
Author
[email protected]
Date
2020-01-15 13:17:50 -0800 (Wed, 15 Jan 2020)

Log Message

[LFC][IFC] LineLayoutContext::nextContentForLine should take LineCandidateContent&
https://bugs.webkit.org/show_bug.cgi?id=206300
<rdar://problem/58612197>

Reviewed by Antti Koivisto.

~5% progression on PerformanceTests/Layout/line-layout-simple.html.
LineLayoutContext::nextContentForLine is hot and LineCandidateContent has Vector members (too heavy).

* layout/inlineformatting/LineLayoutContext.cpp:
(WebCore::Layout::LineCandidateContent::reset):
(WebCore::Layout::LineLayoutContext::layoutLine):
(WebCore::Layout::LineLayoutContext::nextContentForLine):
* layout/inlineformatting/LineLayoutContext.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (254629 => 254630)


--- trunk/Source/WebCore/ChangeLog	2020-01-15 20:42:34 UTC (rev 254629)
+++ trunk/Source/WebCore/ChangeLog	2020-01-15 21:17:50 UTC (rev 254630)
@@ -1,5 +1,22 @@
 2020-01-15  Zalan Bujtas  <[email protected]>
 
+        [LFC][IFC] LineLayoutContext::nextContentForLine should take LineCandidateContent&
+        https://bugs.webkit.org/show_bug.cgi?id=206300
+        <rdar://problem/58612197>
+
+        Reviewed by Antti Koivisto.
+
+        ~5% progression on PerformanceTests/Layout/line-layout-simple.html.
+        LineLayoutContext::nextContentForLine is hot and LineCandidateContent has Vector members (too heavy).
+
+        * layout/inlineformatting/LineLayoutContext.cpp:
+        (WebCore::Layout::LineCandidateContent::reset):
+        (WebCore::Layout::LineLayoutContext::layoutLine):
+        (WebCore::Layout::LineLayoutContext::nextContentForLine):
+        * layout/inlineformatting/LineLayoutContext.h:
+
+2020-01-15  Zalan Bujtas  <[email protected]>
+
         [LFC][IFC] ContinuousContent should not need a copy of RunList
         https://bugs.webkit.org/show_bug.cgi?id=206293
         <rdar://problem/58607446>

Modified: trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp (254629 => 254630)


--- trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp	2020-01-15 20:42:34 UTC (rev 254629)
+++ trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.cpp	2020-01-15 21:17:50 UTC (rev 254630)
@@ -185,6 +185,8 @@
 
     const InlineItem* trailingLineBreak() const { return m_trailingLineBreak; }
 
+    void reset();
+
 private:
     void setTrailingLineBreak(const InlineItem& lineBreakItem) { m_trailingLineBreak = &lineBreakItem; }
 
@@ -203,6 +205,13 @@
     m_inlineRuns.append({ inlineItem, *logicalWidth });
 }
 
+void LineCandidateContent::reset()
+{
+    m_inlineRuns.clear();
+    m_floats.clear();
+    m_trailingLineBreak = nullptr;
+}
+
 static InlineLayoutUnit inlineItemWidth(const FormattingContext& formattingContext, const InlineItem& inlineItem, InlineLayoutUnit contentLogicalLeft)
 {
     if (inlineItem.isLineBreak())
@@ -258,12 +267,13 @@
     auto lineBreaker = LineBreaker { };
     auto currentItemIndex = leadingInlineItemIndex;
     unsigned committedInlineItemCount = 0;
+    auto candidateContent = LineCandidateContent { };
     while (currentItemIndex < m_inlineItems.size()) {
         // 1. Collect the set of runs that we can commit to the line as one entity e.g. <span>text_and_span_start_span_end</span>.
         // 2. Apply floats and shrink the available horizontal space e.g. <span>intru_<div style="float: left"></div>sive_float</span>.
         // 3. Check if the content fits the line and commit the content accordingly (full, partial or not commit at all).
         // 4. Return if we are at the end of the line either by not being able to fit more content or because of an explicit line break.
-        auto candidateContent = nextContentForLine(currentItemIndex, partialLeadingContentLength, line.lineBox().logicalWidth());
+        nextContentForLine(candidateContent, currentItemIndex, partialLeadingContentLength, line.lineBox().logicalWidth());
         if (candidateContent.hasIntrusiveFloats()) {
             // Add floats first because they shrink the available horizontal space for the rest of the content.
             auto result = tryAddingFloatItems(line, candidateContent.floats());
@@ -328,9 +338,10 @@
     return LineContent { trailingInlineItemIndex, partialContent, WTFMove(m_floats), line.close(isLastLineWithInlineContent), line.lineBox() };
 }
 
-LineCandidateContent LineLayoutContext::nextContentForLine(unsigned inlineItemIndex, Optional<unsigned> partialLeadingContentLength, InlineLayoutUnit currentLogicalRight)
+void LineLayoutContext::nextContentForLine(LineCandidateContent& candidateContent, unsigned inlineItemIndex, Optional<unsigned> partialLeadingContentLength, InlineLayoutUnit currentLogicalRight)
 {
     ASSERT(inlineItemIndex < m_inlineItems.size());
+    candidateContent.reset();
     // 1. Simply add any overflow content from the previous line to the candidate content. It's always a text content.
     // 2. Find the next soft wrap position or explicit line break.
     // 3. Collect floats between the inline content.
@@ -338,7 +349,6 @@
     // softWrapOpportunityIndex == m_inlineItems.size() means we don't have any wrap opportunity in this content.
     ASSERT(softWrapOpportunityIndex <= m_inlineItems.size());
 
-    auto candidateContent = LineCandidateContent { };
     if (partialLeadingContentLength) {
         // Handle leading partial content first (split text from the previous line).
         // Construct a partial leading inline item.
@@ -361,7 +371,6 @@
         candidateContent.append(inlineItem, inlineItenmWidth);
         currentLogicalRight += inlineItenmWidth;
     }
-    return candidateContent;
 }
 
 LineLayoutContext::Result LineLayoutContext::tryAddingFloatItems(LineBuilder& line, const FloatList& floats)

Modified: trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.h (254629 => 254630)


--- trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.h	2020-01-15 20:42:34 UTC (rev 254629)
+++ trunk/Source/WebCore/layout/inlineformatting/LineLayoutContext.h	2020-01-15 21:17:50 UTC (rev 254630)
@@ -54,7 +54,7 @@
     using FloatList = Vector<WeakPtr<InlineItem>>;
 
 private:
-    LineCandidateContent nextContentForLine(unsigned inlineItemIndex, Optional<unsigned> overflowLength, InlineLayoutUnit currentLogicalRight);
+    void nextContentForLine(LineCandidateContent&, unsigned inlineItemIndex, Optional<unsigned> overflowLength, InlineLayoutUnit currentLogicalRight);
     struct Result {
         LineBreaker::IsEndOfLine isEndOfLine { LineBreaker::IsEndOfLine::No };
         size_t committedCount { 0 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to