<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[211456] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/211456">211456</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2017-01-31 16:01:26 -0800 (Tue, 31 Jan 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Simple line layout: Collect fragments in LineState only when needed for post-processing.
https://bugs.webkit.org/show_bug.cgi?id=167655
&lt;rdar://problem/30290592&gt;

Reviewed by Antti Koivisto.

The fragments we need to keep around for basic line breaking are the last and last non-whitespace fragments.
However in certain cases such as text-align: justify, we have to traverse the entire line
at post-processing which requires all the fragments on the current line.
This patch speeds up the basic line handling by using m_fragment list only for the special cases.
It improves PerformanceTests/Layout/simple-line-layout-non-repeating-text.html by ~7% (local measurement)
median: 114.25 runs/s -&gt; median: 122.16 runs

Covered by existing tests.

* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::LineState::setNeedsAllFragments):
(WebCore::SimpleLineLayout::LineState::hasTrailingWhitespace):
(WebCore::SimpleLineLayout::LineState::lastFragment):
(WebCore::SimpleLineLayout::LineState::expansionOpportunityCount):
(WebCore::SimpleLineLayout::LineState::isEmpty):
(WebCore::SimpleLineLayout::LineState::endPositionForCollapsedFragment):
(WebCore::SimpleLineLayout::LineState::appendFragmentAndCreateRunIfNeeded): Track uncompleted width.
(WebCore::SimpleLineLayout::LineState::revertToLastCompleteFragment):
(WebCore::SimpleLineLayout::LineState::removeTrailingWhitespace):
(WebCore::SimpleLineLayout::removeTrailingWhitespace):
(WebCore::SimpleLineLayout::updateLineConstrains): Set the slow path for text-align: justify.
(WebCore::SimpleLineLayout::createLineRuns):
(WebCore::SimpleLineLayout::closeLineEndingAndAdjustRuns):
(WebCore::SimpleLineLayout::createTextRuns):
* rendering/SimpleLineLayoutTextFragmentIterator.h:
(WebCore::SimpleLineLayout::TextFragmentIterator::TextFragment::isValid):
(WebCore::SimpleLineLayout::TextFragmentIterator::TextFragment::length):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutcpp">trunk/Source/WebCore/rendering/SimpleLineLayout.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutTextFragmentIteratorh">trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (211455 => 211456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-01-31 23:49:10 UTC (rev 211455)
+++ trunk/Source/WebCore/ChangeLog        2017-02-01 00:01:26 UTC (rev 211456)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2017-01-31  Zalan Bujtas  &lt;zalan@apple.com&gt;
+
+        Simple line layout: Collect fragments in LineState only when needed for post-processing.
+        https://bugs.webkit.org/show_bug.cgi?id=167655
+        &lt;rdar://problem/30290592&gt;
+
+        Reviewed by Antti Koivisto.
+
+        The fragments we need to keep around for basic line breaking are the last and last non-whitespace fragments.
+        However in certain cases such as text-align: justify, we have to traverse the entire line
+        at post-processing which requires all the fragments on the current line.
+        This patch speeds up the basic line handling by using m_fragment list only for the special cases.
+        It improves PerformanceTests/Layout/simple-line-layout-non-repeating-text.html by ~7% (local measurement)
+        median: 114.25 runs/s -&gt; median: 122.16 runs
+
+        Covered by existing tests.
+
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::LineState::setNeedsAllFragments):
+        (WebCore::SimpleLineLayout::LineState::hasTrailingWhitespace):
+        (WebCore::SimpleLineLayout::LineState::lastFragment):
+        (WebCore::SimpleLineLayout::LineState::expansionOpportunityCount):
+        (WebCore::SimpleLineLayout::LineState::isEmpty):
+        (WebCore::SimpleLineLayout::LineState::endPositionForCollapsedFragment):
+        (WebCore::SimpleLineLayout::LineState::appendFragmentAndCreateRunIfNeeded): Track uncompleted width.
+        (WebCore::SimpleLineLayout::LineState::revertToLastCompleteFragment):
+        (WebCore::SimpleLineLayout::LineState::removeTrailingWhitespace):
+        (WebCore::SimpleLineLayout::removeTrailingWhitespace):
+        (WebCore::SimpleLineLayout::updateLineConstrains): Set the slow path for text-align: justify.
+        (WebCore::SimpleLineLayout::createLineRuns):
+        (WebCore::SimpleLineLayout::closeLineEndingAndAdjustRuns):
+        (WebCore::SimpleLineLayout::createTextRuns):
+        * rendering/SimpleLineLayoutTextFragmentIterator.h:
+        (WebCore::SimpleLineLayout::TextFragmentIterator::TextFragment::isValid):
+        (WebCore::SimpleLineLayout::TextFragmentIterator::TextFragment::length):
+
</ins><span class="cx"> 2017-01-31  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         com.apple.WebKit.WebContent.Development crashed in com.apple.WebCore: WebCore::FrameView::didDestroyRenderTree
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayout.cpp (211455 => 211456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2017-01-31 23:49:10 UTC (rev 211455)
+++ trunk/Source/WebCore/rendering/SimpleLineLayout.cpp        2017-02-01 00:01:26 UTC (rev 211456)
</span><span class="lines">@@ -406,17 +406,17 @@
</span><span class="cx">     void setCollapedWhitespaceWidth(float width) { m_collapsedWhitespaceWidth = width; }
</span><span class="cx">     void setLogicalLeftOffset(float offset) { m_logicalLeftOffset = offset; }
</span><span class="cx">     void setOverflowedFragment(const TextFragmentIterator::TextFragment&amp; fragment) { m_overflowedFragment = fragment; }
</span><ins>+    void setNeedsAllFragments()
+    {
+        ASSERT(!m_fragments);
+        m_fragments.emplace();
+    }
</ins><span class="cx"> 
</span><span class="cx">     float availableWidth() const { return m_availableWidth; }
</span><span class="cx">     float logicalLeftOffset() const { return m_logicalLeftOffset; }
</span><span class="cx">     const TextFragmentIterator::TextFragment&amp; overflowedFragment() const { return m_overflowedFragment; }
</span><del>-    bool hasTrailingWhitespace() const { return m_trailingWhitespaceLength; }
-    std::optional&lt;TextFragmentIterator::TextFragment&gt; lastFragment() const
-    {
-        if (m_fragments.size())
-            return m_fragments.last();
-        return std::nullopt;
-    }
</del><ins>+    bool hasTrailingWhitespace() const { return m_lastFragment.type() == TextFragmentIterator::TextFragment::Whitespace; }
+    TextFragmentIterator::TextFragment lastFragment() const { return m_lastFragment; }
</ins><span class="cx">     bool isWhitespaceOnly() const { return m_trailingWhitespaceWidth &amp;&amp; m_runsWidth == m_trailingWhitespaceWidth; }
</span><span class="cx">     bool fits(float extra) const { return m_availableWidth &gt;= m_runsWidth + extra; }
</span><span class="cx">     bool firstCharacterFits() const { return m_firstCharacterFits; }
</span><span class="lines">@@ -423,12 +423,13 @@
</span><span class="cx">     float width() const { return m_runsWidth; }
</span><span class="cx">     std::pair&lt;unsigned, bool&gt; expansionOpportunityCount(unsigned from, unsigned to) const
</span><span class="cx">     {
</span><ins>+        ASSERT(m_fragments);
</ins><span class="cx">         // linebreak runs are special.
</span><span class="cx">         if (from == to)
</span><span class="cx">             return std::make_pair(0, false);
</span><span class="cx">         unsigned expansionOpportunityCount = 0;
</span><span class="cx">         auto previousFragmentType = TextFragmentIterator::TextFragment::ContentEnd;
</span><del>-        for (const auto&amp; fragment : m_fragments) {
</del><ins>+        for (const auto&amp; fragment : *m_fragments) {
</ins><span class="cx">             if (fragment.end() &lt;= from)
</span><span class="cx">                 continue;
</span><span class="cx">             auto currentFragmentType = fragment.type();
</span><span class="lines">@@ -445,36 +446,44 @@
</span><span class="cx"> 
</span><span class="cx">     bool isEmpty() const
</span><span class="cx">     {
</span><del>-        if (!m_fragments.size())
</del><ins>+        if (!m_lastFragment.isValid())
</ins><span class="cx">             return true;
</span><span class="cx">         if (!m_lastCompleteFragment.isEmpty())
</span><span class="cx">             return false;
</span><del>-        return m_fragments.last().overlapsToNextRenderer();
</del><ins>+        return m_lastFragment.overlapsToNextRenderer();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    static inline unsigned endPositionForCollapsedFragment(const TextFragmentIterator::TextFragment&amp; fragment)
+    {
+        return fragment.isCollapsed() ? fragment.start() + 1 : fragment.end();
+    }
+
</ins><span class="cx">     void appendFragmentAndCreateRunIfNeeded(const TextFragmentIterator::TextFragment&amp; fragment, Layout::RunVector&amp; runs)
</span><span class="cx">     {
</span><span class="cx">         // Adjust end position while collapsing.
</span><del>-        unsigned endPosition = fragment.isCollapsed() ? fragment.start() + 1 : fragment.end();
</del><ins>+        unsigned endPosition = endPositionForCollapsedFragment(fragment);
</ins><span class="cx">         // New line needs new run.
</span><del>-        if (!m_runsWidth)
</del><ins>+        if (!m_runsWidth) {
+            ASSERT(!m_uncompletedWidth);
</ins><span class="cx">             runs.append(Run(fragment.start(), endPosition, m_runsWidth, m_runsWidth + fragment.width(), false, fragment.hasHyphen()));
</span><del>-        else {
-            auto&amp; lastFragment = m_fragments.last();
</del><ins>+        } else {
</ins><span class="cx">             // Advance last completed fragment when the previous fragment is all set (including multiple parts across renderers)
</span><del>-            if ((lastFragment.type() != fragment.type()) || !lastFragment.overlapsToNextRenderer())
-                m_lastCompleteFragment = lastFragment;
</del><ins>+            if ((m_lastFragment.type() != fragment.type()) || !m_lastFragment.overlapsToNextRenderer()) {
+                m_lastCompleteFragment = m_lastFragment;
+                m_uncompletedWidth = fragment.width();
+            } else
+                m_uncompletedWidth += fragment.width();
</ins><span class="cx">             // Collapse neighbouring whitespace, if they are across multiple renderers and are not collapsed yet.
</span><del>-            if (lastFragment.isCollapsible() &amp;&amp; fragment.isCollapsible()) {
-                ASSERT(lastFragment.isLastInRenderer());
-                if (!lastFragment.isCollapsed()) {
-                    // Line width needs to be reset so that now it takes collapsing into consideration.
-                    m_runsWidth -= (lastFragment.width() - m_collapsedWhitespaceWidth);
</del><ins>+            if (m_lastFragment.isCollapsible() &amp;&amp; fragment.isCollapsible()) {
+                ASSERT(m_lastFragment.isLastInRenderer());
+                if (!m_lastFragment.isCollapsed()) {
+                    // Line width needs to be adjusted so that now it takes collapsing into consideration.
+                    m_runsWidth -= (m_lastFragment.width() - m_collapsedWhitespaceWidth);
</ins><span class="cx">                 }
</span><span class="cx">                 // This fragment is collapsed completely. No run is needed.
</span><span class="cx">                 return;
</span><span class="cx">             }
</span><del>-            if (lastFragment.isLastInRenderer() || lastFragment.isCollapsed())
</del><ins>+            if (m_lastFragment.isLastInRenderer() || m_lastFragment.isCollapsed())
</ins><span class="cx">                 runs.append(Run(fragment.start(), endPosition, m_runsWidth, m_runsWidth + fragment.width(), false, fragment.hasHyphen()));
</span><span class="cx">             else {
</span><span class="cx">                 Run&amp; lastRun = runs.last();
</span><span class="lines">@@ -484,15 +493,16 @@
</span><span class="cx">                 lastRun.hasHyphen = fragment.hasHyphen();
</span><span class="cx">             }
</span><span class="cx">         }
</span><del>-        m_fragments.append(fragment);
</del><span class="cx">         m_runsWidth += fragment.width();
</span><ins>+        m_lastFragment = fragment;
+        if (m_fragments)
+            (*m_fragments).append(fragment);
</ins><span class="cx"> 
</span><del>-        if (fragment.type() == TextFragmentIterator::TextFragment::Whitespace) {
-            m_trailingWhitespaceLength += endPosition - fragment.start();
</del><ins>+        if (fragment.type() == TextFragmentIterator::TextFragment::Whitespace)
</ins><span class="cx">             m_trailingWhitespaceWidth += fragment.width();
</span><del>-        } else {
-            m_trailingWhitespaceLength = 0;
</del><ins>+        else {
</ins><span class="cx">             m_trailingWhitespaceWidth = 0;
</span><ins>+            m_lastNonWhitespaceFragment = fragment;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (!m_firstCharacterFits)
</span><span class="lines">@@ -501,46 +511,28 @@
</span><span class="cx"> 
</span><span class="cx">     TextFragmentIterator::TextFragment revertToLastCompleteFragment(Layout::RunVector&amp; runs)
</span><span class="cx">     {
</span><del>-        ASSERT(m_fragments.size());
-        unsigned revertLength = 0;
-        float revertWidth = 0;
-        while (m_fragments.size()) {
-            const auto&amp; current = m_fragments.last();
-            if (current == m_lastCompleteFragment)
-                break;
-            revertLength += current.end() - current.start();
-            revertWidth += current.width();
-            m_fragments.removeLast();
</del><ins>+        if (!m_uncompletedWidth) {
+            ASSERT(m_lastFragment == m_lastCompleteFragment);
+            return m_lastFragment;
</ins><span class="cx">         }
</span><del>-        m_runsWidth -= revertWidth;
-        if (revertLength)
-            revertRuns(runs, revertLength, revertWidth);
</del><ins>+        ASSERT(m_lastFragment.isValid());
+        m_runsWidth -= m_uncompletedWidth;
+        revertRuns(runs, endPositionForCollapsedFragment(m_lastFragment) - endPositionForCollapsedFragment(m_lastCompleteFragment), m_uncompletedWidth);
+        m_uncompletedWidth = 0;
+        ASSERT(m_lastCompleteFragment.isValid());
</ins><span class="cx">         return m_lastCompleteFragment;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void removeTrailingWhitespace(Layout::RunVector&amp; runs)
</span><span class="cx">     {
</span><del>-        if (!m_trailingWhitespaceLength)
</del><ins>+        if (m_lastFragment.type() != TextFragmentIterator::TextFragment::Whitespace)
</ins><span class="cx">             return;
</span><del>-        revertRuns(runs, m_trailingWhitespaceLength, m_trailingWhitespaceWidth);
</del><ins>+        ASSERT(m_trailingWhitespaceWidth);
+        ASSERT(m_lastFragment.end() != m_lastNonWhitespaceFragment.end());
+        unsigned trailingWhitespaceLength = endPositionForCollapsedFragment(m_lastFragment) - m_lastNonWhitespaceFragment.end();
+        revertRuns(runs, trailingWhitespaceLength, m_trailingWhitespaceWidth);
</ins><span class="cx">         m_runsWidth -= m_trailingWhitespaceWidth;
</span><del>-        ASSERT(m_fragments.last().type() == TextFragmentIterator::TextFragment::Whitespace);
-        while (m_fragments.size()) {
-            const auto&amp; current = m_fragments.last();
-            if (current.type() != TextFragmentIterator::TextFragment::Whitespace)
-                break;
-#if !ASSERT_DISABLED
-            m_trailingWhitespaceLength -= (current.isCollapsed() ? 1 : current.end() - current.start());
-            m_trailingWhitespaceWidth -= current.width();
-#endif
-            m_fragments.removeLast();
-        }
-#if !ASSERT_DISABLED
-        ASSERT(!m_trailingWhitespaceLength);
-        ASSERT(!m_trailingWhitespaceWidth);
-#endif
-        m_trailingWhitespaceLength = 0;
-        m_trailingWhitespaceWidth = 0;
</del><ins>+        m_lastFragment = m_lastNonWhitespaceFragment;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -552,17 +544,18 @@
</span><span class="cx"> 
</span><span class="cx">     float m_availableWidth { 0 };
</span><span class="cx">     float m_logicalLeftOffset { 0 };
</span><ins>+    float m_runsWidth { 0 };
</ins><span class="cx">     TextFragmentIterator::TextFragment m_overflowedFragment;
</span><del>-    float m_runsWidth { 0 };
</del><ins>+    TextFragmentIterator::TextFragment m_lastFragment;
+    TextFragmentIterator::TextFragment m_lastNonWhitespaceFragment;
</ins><span class="cx">     TextFragmentIterator::TextFragment m_lastCompleteFragment;
</span><ins>+    float m_uncompletedWidth { 0 };
</ins><span class="cx">     float m_trailingWhitespaceWidth { 0 }; // Use this to remove trailing whitespace without re-mesuring the text.
</span><del>-    unsigned m_trailingWhitespaceLength { 0 };
</del><span class="cx">     float m_collapsedWhitespaceWidth { 0 };
</span><span class="cx">     // Having one character on the line does not necessarily mean it actually fits.
</span><span class="cx">     // First character of the first fragment might be forced on to the current line even if it does not fit.
</span><span class="cx">     bool m_firstCharacterFits { false };
</span><del>-    // FIXME: We don't actually need this for all the simple cases. Try to remove/make it optional.
-    Vector&lt;TextFragmentIterator::TextFragment, 30&gt; m_fragments;
</del><ins>+    std::optional&lt;Vector&lt;TextFragmentIterator::TextFragment, 30&gt;&gt; m_fragments;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> class FragmentForwardIterator : public std::iterator&lt;std::forward_iterator_tag, unsigned&gt; {
</span><span class="lines">@@ -598,20 +591,18 @@
</span><span class="cx"> {
</span><span class="cx">     if (!lineState.hasTrailingWhitespace())
</span><span class="cx">         return;
</span><del>-
-    // Remove collapsed whitespace, or non-collapsed pre-wrap whitespace, unless it's the only content on the line -so removing the whitesapce would produce an empty line.
</del><ins>+    // Remove collapsed whitespace, or non-collapsed pre-wrap whitespace, unless it's the only content on the line -so removing the whitesapce
+    // would produce an empty line.
</ins><span class="cx">     const auto&amp; style = textFragmentIterator.style();
</span><span class="cx">     bool collapseWhitespace = style.collapseWhitespace | preWrap(style);
</span><span class="cx">     if (!collapseWhitespace)
</span><span class="cx">         return;
</span><del>-
</del><span class="cx">     if (preWrap(style) &amp;&amp; lineState.isWhitespaceOnly())
</span><span class="cx">         return;
</span><del>-
</del><span class="cx">     lineState.removeTrailingWhitespace(runs);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void updateLineConstrains(const RenderBlockFlow&amp; flow, LineState&amp; line, bool isFirstLine)
</del><ins>+static void updateLineConstrains(const RenderBlockFlow&amp; flow, LineState&amp; line, const TextFragmentIterator::Style&amp; style, bool isFirstLine)
</ins><span class="cx"> {
</span><span class="cx">     bool shouldApplyTextIndent = !flow.isAnonymous() || flow.parent()-&gt;firstChild() == &amp;flow;
</span><span class="cx">     LayoutUnit height = flow.logicalHeight();
</span><span class="lines">@@ -620,6 +611,8 @@
</span><span class="cx">     line.setLogicalLeftOffset(flow.logicalLeftOffsetForLine(height, DoNotIndentText, logicalHeight) +
</span><span class="cx">         (shouldApplyTextIndent &amp;&amp; isFirstLine ? flow.textIndentOffset() : LayoutUnit(0)));
</span><span class="cx">     line.setAvailableWidth(std::max&lt;float&gt;(0, logicalRightOffset - line.logicalLeftOffset()));
</span><ins>+    if (style.textAlign == JUSTIFY)
+        line.setNeedsAllFragments();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static std::optional&lt;unsigned&gt; hyphenPositionForFragment(unsigned splitPosition, TextFragmentIterator::TextFragment&amp; fragmentToSplit,
</span><span class="lines">@@ -792,11 +785,10 @@
</span><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">             // Non-breakable non-whitespace fragment when there's already content on the line. Push it to the next line.
</span><del>-            ASSERT(line.lastFragment());
-            if (line.lastFragment().value().overlapsToNextRenderer()) {
</del><ins>+            ASSERT(line.lastFragment().isValid());
+            if (line.lastFragment().overlapsToNextRenderer()) {
</ins><span class="cx">                 // Check if this fragment is a continuation of a previous segment. In such cases, we need to remove them all.
</span><del>-                const auto&amp; lastCompleteFragment = line.revertToLastCompleteFragment(runs);
-                textFragmentIterator.revertToEndOfFragment(lastCompleteFragment);
</del><ins>+                textFragmentIterator.revertToEndOfFragment(line.revertToLastCompleteFragment(runs));
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx">             line.setOverflowedFragment(fragment);
</span><span class="lines">@@ -874,7 +866,7 @@
</span><span class="cx">     const auto&amp; style = textFragmentIterator.style();
</span><span class="cx">     auto firstRunIndex = lastRunIndexOfPreviousLine ? lastRunIndexOfPreviousLine.value() + 1 : 0;
</span><span class="cx">     auto lineLogicalLeft = line.logicalLeftOffset();
</span><del>-    auto textAlign = textAlignForLine(style, lastLineInFlow || (line.lastFragment() &amp;&amp; line.lastFragment().value().type() == TextFragmentIterator::TextFragment::HardLineBreak));
</del><ins>+    auto textAlign = textAlignForLine(style, lastLineInFlow || (line.lastFragment().isValid() &amp;&amp; line.lastFragment().type() == TextFragmentIterator::TextFragment::HardLineBreak));
</ins><span class="cx">     if (textAlign == JUSTIFY)
</span><span class="cx">         justifyRuns(line, runs, firstRunIndex);
</span><span class="cx">     else
</span><span class="lines">@@ -899,7 +891,7 @@
</span><span class="cx">         flow.setLogicalHeight(lineHeight * lineCount + borderAndPaddingBefore);
</span><span class="cx">         LineState previousLine = line;
</span><span class="cx">         line = LineState();
</span><del>-        updateLineConstrains(flow, line, !lineCount);
</del><ins>+        updateLineConstrains(flow, line, textFragmentIterator.style(), !lineCount);
</ins><span class="cx">         isEndOfContent = createLineRuns(line, previousLine, runs, textFragmentIterator);
</span><span class="cx">         closeLineEndingAndAdjustRuns(line, runs, lastRunIndexOfPreviousLine, lineCount, textFragmentIterator, isEndOfContent);
</span><span class="cx">         if (runs.size())
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutTextFragmentIteratorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h (211455 => 211456)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h        2017-01-31 23:49:10 UTC (rev 211455)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h        2017-02-01 00:01:26 UTC (rev 211456)
</span><span class="lines">@@ -41,7 +41,7 @@
</span><span class="cx">     TextFragmentIterator(const RenderBlockFlow&amp;);
</span><span class="cx">     class TextFragment {
</span><span class="cx">     public:
</span><del>-        enum Type { ContentEnd, SoftLineBreak, HardLineBreak, Whitespace, NonWhitespace };
</del><ins>+        enum Type { Invalid, ContentEnd, SoftLineBreak, HardLineBreak, Whitespace, NonWhitespace };
</ins><span class="cx">         TextFragment() = default;
</span><span class="cx">         TextFragment(unsigned start, unsigned end, float width, Type type, bool isLastInRenderer = false, bool overlapsToNextRenderer = false, bool isCollapsed = false, bool isCollapsible = false)
</span><span class="cx">             : m_start(start)
</span><span class="lines">@@ -55,8 +55,10 @@
</span><span class="cx">         {
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        bool isValid() const { return m_type != Invalid; }
</ins><span class="cx">         unsigned start() const { return m_start; }
</span><span class="cx">         unsigned end() const { return m_end; }
</span><ins>+        unsigned length() const { ASSERT(m_end &gt;= m_start); return m_end - m_start; }
</ins><span class="cx">         float width() const { return m_width; }
</span><span class="cx">         Type type() const { return m_type; }
</span><span class="cx">         bool overlapsToNextRenderer() const { return m_overlapsToNextRenderer; }
</span><span class="lines">@@ -87,7 +89,7 @@
</span><span class="cx">         unsigned m_start { 0 };
</span><span class="cx">         unsigned m_end { 0 };
</span><span class="cx">         float m_width { 0 };
</span><del>-        Type m_type { NonWhitespace };
</del><ins>+        Type m_type { Invalid };
</ins><span class="cx">         bool m_isLastInRenderer { false };
</span><span class="cx">         bool m_overlapsToNextRenderer { false };
</span><span class="cx">         bool m_isCollapsed { false };
</span></span></pre>
</div>
</div>

</body>
</html>