<!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>[176528] trunk</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/176528">176528</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2014-11-24 16:15:46 -0800 (Mon, 24 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Avoid String concatenation with line break iterator
https://bugs.webkit.org/show_bug.cgi?id=139034

Reviewed by Zalan Bujtas.

Source/WebCore:

Test: fast/text/simple-lines-multiple-renderers-break.html

* rendering/SimpleLineLayoutFlowContents.cpp:
(WebCore::SimpleLineLayout::initializeSegments):

    Include String too so it doesn't need to be fetched from the renderer.

(WebCore::SimpleLineLayout::FlowContents::FlowContents):
(WebCore::SimpleLineLayout::FlowContents::findNextBreakablePosition):

    Make this iterative instead of recursive.
    Uset setPriorContext to provide previous characters instead of concatenating
    the string from all the previous segments.

(WebCore::SimpleLineLayout::findNextNonWhitespace):
(WebCore::SimpleLineLayout::FlowContents::findNextNonWhitespacePosition):

    Search using segments instead of the concatenated string.

(WebCore::SimpleLineLayout::FlowContents::textWidth):
(WebCore::SimpleLineLayout::FlowContents::segmentIndexForPositionSlow):
(WebCore::SimpleLineLayout::FlowContents::runWidth):
(WebCore::SimpleLineLayout::FlowContents::segmentForPositionSlow): Deleted.
(WebCore::SimpleLineLayout::FlowContents::appendNextRendererContentIfNeeded): Deleted.
(WebCore::SimpleLineLayout::FlowContents::nextNonWhitespacePosition): Deleted.
* rendering/SimpleLineLayoutFlowContents.h:
(WebCore::SimpleLineLayout::FlowContents::characterAt):
(WebCore::SimpleLineLayout::FlowContents::isNewlineCharacter):
(WebCore::SimpleLineLayout::FlowContents::segmentIndexForPosition):
(WebCore::SimpleLineLayout::FlowContents::segmentForPosition):

LayoutTests:

Test that there is no implicit break point between Text nodes.

* fast/text/simple-lines-multiple-renderers-break-expected.html: Added.
* fast/text/simple-lines-multiple-renderers-break.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutFlowContentscpp">trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingSimpleLineLayoutFlowContentsh">trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextsimplelinesmultiplerenderersbreakexpectedhtml">trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break-expected.html</a></li>
<li><a href="#trunkLayoutTestsfasttextsimplelinesmultiplerenderersbreakhtml">trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (176527 => 176528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-11-25 00:10:17 UTC (rev 176527)
+++ trunk/LayoutTests/ChangeLog        2014-11-25 00:15:46 UTC (rev 176528)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-11-24  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Avoid String concatenation with line break iterator
+        https://bugs.webkit.org/show_bug.cgi?id=139034
+
+        Reviewed by Zalan Bujtas.
+
+        Test that there is no implicit break point between Text nodes.
+
+        * fast/text/simple-lines-multiple-renderers-break-expected.html: Added.
+        * fast/text/simple-lines-multiple-renderers-break.html: Added.
+
</ins><span class="cx"> 2014-11-24  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         SimpleLineLayout::canUseFor() should iterate through RenderTexts to check if their content is eligible for simple line layout.
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextsimplelinesmultiplerenderersbreakexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break-expected.html (0 => 176528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break-expected.html        2014-11-25 00:15:46 UTC (rev 176528)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;width:300px; border: 2px solid green&quot;&gt;
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextsimplelinesmultiplerenderersbreakhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break.html (0 => 176528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/simple-lines-multiple-renderers-break.html        2014-11-25 00:15:46 UTC (rev 176528)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;Test that there is no break point between simple line layout segments.&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div id=container style=&quot;width:300px; border: 2px solid green&quot;&gt;
+&lt;/div&gt;
+&lt;script&gt;
+var container = document.getElementById(&quot;container&quot;);
+container.appendChild(document.createTextNode(&quot;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&quot;));
+container.appendChild(document.createTextNode(&quot;bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb&quot;));
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (176527 => 176528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-25 00:10:17 UTC (rev 176527)
+++ trunk/Source/WebCore/ChangeLog        2014-11-25 00:15:46 UTC (rev 176528)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2014-11-24  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Avoid String concatenation with line break iterator
+        https://bugs.webkit.org/show_bug.cgi?id=139034
+
+        Reviewed by Zalan Bujtas.
+
+        Test: fast/text/simple-lines-multiple-renderers-break.html
+
+        * rendering/SimpleLineLayoutFlowContents.cpp:
+        (WebCore::SimpleLineLayout::initializeSegments):
+
+            Include String too so it doesn't need to be fetched from the renderer.
+
+        (WebCore::SimpleLineLayout::FlowContents::FlowContents):
+        (WebCore::SimpleLineLayout::FlowContents::findNextBreakablePosition):
+
+            Make this iterative instead of recursive.
+            Uset setPriorContext to provide previous characters instead of concatenating
+            the string from all the previous segments.
+
+        (WebCore::SimpleLineLayout::findNextNonWhitespace):
+        (WebCore::SimpleLineLayout::FlowContents::findNextNonWhitespacePosition):
+
+            Search using segments instead of the concatenated string.
+
+        (WebCore::SimpleLineLayout::FlowContents::textWidth):
+        (WebCore::SimpleLineLayout::FlowContents::segmentIndexForPositionSlow):
+        (WebCore::SimpleLineLayout::FlowContents::runWidth):
+        (WebCore::SimpleLineLayout::FlowContents::segmentForPositionSlow): Deleted.
+        (WebCore::SimpleLineLayout::FlowContents::appendNextRendererContentIfNeeded): Deleted.
+        (WebCore::SimpleLineLayout::FlowContents::nextNonWhitespacePosition): Deleted.
+        * rendering/SimpleLineLayoutFlowContents.h:
+        (WebCore::SimpleLineLayout::FlowContents::characterAt):
+        (WebCore::SimpleLineLayout::FlowContents::isNewlineCharacter):
+        (WebCore::SimpleLineLayout::FlowContents::segmentIndexForPosition):
+        (WebCore::SimpleLineLayout::FlowContents::segmentForPosition):
+
</ins><span class="cx"> 2014-11-24  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         SimpleLineLayout::canUseFor() should iterate through RenderTexts to check if their content is eligible for simple line layout.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutFlowContentscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp (176527 => 176528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp        2014-11-25 00:10:17 UTC (rev 176527)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.cpp        2014-11-25 00:15:46 UTC (rev 176528)
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">     unsigned startPosition = 0;
</span><span class="cx">     for (auto&amp; textChild : childrenOfType&lt;RenderText&gt;(flow)) {
</span><span class="cx">         unsigned textLength = textChild.text()-&gt;length();
</span><del>-        segments.append(FlowContents::Segment { startPosition, startPosition + textLength, textChild });
</del><ins>+        segments.append(FlowContents::Segment { startPosition, startPosition + textLength, textChild.text(), textChild });
</ins><span class="cx">         startPosition += textLength;
</span><span class="cx">     }
</span><span class="cx">     return segments;
</span><span class="lines">@@ -61,28 +61,55 @@
</span><span class="cx"> FlowContents::FlowContents(const RenderBlockFlow&amp; flow)
</span><span class="cx">     : m_style(flow.style())
</span><span class="cx">     , m_segments(initializeSegments(flow))
</span><del>-    , m_lineBreakIterator(downcast&lt;RenderText&gt;(*flow.firstChild()).text(), flow.style().locale())
</del><ins>+    , m_lineBreakIterator(m_segments[0].text, flow.style().locale())
</ins><span class="cx">     , m_lastSegmentIndex(0)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> unsigned FlowContents::findNextBreakablePosition(unsigned position) const
</span><span class="cx"> {
</span><del>-    String string = m_lineBreakIterator.string();
-    unsigned breakablePosition = nextBreakablePositionNonLoosely&lt;LChar, NBSPBehavior::IgnoreNBSP&gt;(m_lineBreakIterator, string.characters8(), string.length(), position);
-    if (appendNextRendererContentIfNeeded(breakablePosition))
-        return findNextBreakablePosition(position);
-    ASSERT(breakablePosition &gt;= position);
-    return breakablePosition;
</del><ins>+    while (!isEnd(position)) {
+        auto&amp; segment = segmentForPosition(position);
+        if (segment.text.impl() != m_lineBreakIterator.string().impl()) {
+            UChar lastCharacter = segment.start &gt; 0 ? characterAt(segment.start - 1) : 0;
+            UChar secondToLastCharacter = segment.start &gt; 1 ? characterAt(segment.start - 2) : 0;
+            m_lineBreakIterator.setPriorContext(lastCharacter, secondToLastCharacter);
+            m_lineBreakIterator.resetStringAndReleaseIterator(segment.text, m_style.locale, LineBreakIteratorModeUAX14);
+        }
+
+        auto* characters = segment.text.characters8();
+        unsigned segmentLength = segment.end - segment.start;
+        unsigned segmentPosition = position - segment.start;
+        unsigned breakable = nextBreakablePositionNonLoosely&lt;LChar, NBSPBehavior::IgnoreNBSP&gt;(m_lineBreakIterator, characters, segmentLength, segmentPosition);
+        position = segment.start + breakable;
+        if (position &lt; segment.end)
+            break;
+    }
+    return position;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static bool findNextNonWhitespace(const FlowContents::Segment&amp; segment, const FlowContents::Style&amp; style, unsigned&amp; position, unsigned&amp; spaceCount)
+{
+    const LChar* text = segment.text.characters8();
+    for (; position &lt; segment.end; ++position) {
+        auto character = text[position - segment.start];
+        bool isSpace = character == ' ';
+        bool isWhitespace = isSpace || character == '\t' || (!style.preserveNewline &amp;&amp; character == '\n');
+        if (!isWhitespace)
+            return true;
+        if (isSpace)
+            ++spaceCount;
+    }
+    return false;
+}
+
</ins><span class="cx"> unsigned FlowContents::findNextNonWhitespacePosition(unsigned position, unsigned&amp; spaceCount) const
</span><span class="cx"> {
</span><del>-    unsigned nonWhitespacePosition = nextNonWhitespacePosition(position, spaceCount);
-    if (appendNextRendererContentIfNeeded(nonWhitespacePosition))
-        return findNextNonWhitespacePosition(position, spaceCount);
-    ASSERT(nonWhitespacePosition &gt;= position);
-    return nonWhitespacePosition;
</del><ins>+    for (unsigned i = segmentIndexForPosition(position); i &lt; m_segments.size(); ++i) {
+        if (findNextNonWhitespace(m_segments[i], m_style, position, spaceCount))
+            break;
+    }
+    return position;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> float FlowContents::textWidth(unsigned from, unsigned to, float xPosition) const
</span><span class="lines">@@ -97,7 +124,7 @@
</span><span class="cx">     unsigned fragmentEnd = 0;
</span><span class="cx">     while (true) {
</span><span class="cx">         fragmentEnd = std::min(to, segment-&gt;end);
</span><del>-        textWidth += runWidth(segment-&gt;renderer, from - segment-&gt;start, fragmentEnd - segment-&gt;start, xPosition + textWidth);
</del><ins>+        textWidth += runWidth(segment-&gt;text, from - segment-&gt;start, fragmentEnd - segment-&gt;start, xPosition + textWidth);
</ins><span class="cx">         if (fragmentEnd == to)
</span><span class="cx">             break;
</span><span class="cx">         from = fragmentEnd;
</span><span class="lines">@@ -107,14 +134,15 @@
</span><span class="cx">     return textWidth;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-const FlowContents::Segment&amp; FlowContents::segmentForPositionSlow(unsigned position) const
</del><ins>+unsigned FlowContents::segmentIndexForPositionSlow(unsigned position) const
</ins><span class="cx"> {
</span><span class="cx">     auto it = std::lower_bound(m_segments.begin(), m_segments.end(), position, [](const Segment&amp; segment, unsigned position) {
</span><span class="cx">         return segment.end &lt;= position;
</span><span class="cx">     });
</span><span class="cx">     ASSERT(it != m_segments.end());
</span><del>-    m_lastSegmentIndex = it - m_segments.begin();
-    return *it;
</del><ins>+    auto index = it - m_segments.begin();
+    m_lastSegmentIndex = index;
+    return index;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> const FlowContents::Segment&amp; FlowContents::segmentForRenderer(const RenderText&amp; renderer) const
</span><span class="lines">@@ -127,45 +155,13 @@
</span><span class="cx">     return m_segments.last();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool FlowContents::appendNextRendererContentIfNeeded(unsigned position) const
</del><ins>+float FlowContents::runWidth(const String&amp; text, unsigned from, unsigned to, float xPosition) const
</ins><span class="cx"> {
</span><del>-    if (isEnd(position))
-        return false;
-    String string = m_lineBreakIterator.string();
-    if (position &lt; string.length())
-        return false;
-
-    // Content needs to be requested sequentially.
-    ASSERT(position == string.length());
-    auto&amp; segment = segmentForPosition(position);
-
-    m_lineBreakIterator.resetStringAndReleaseIterator(string + String(segment.renderer.text()), m_style.locale, LineBreakIteratorModeUAX14);
-    return true;
-}
-
-unsigned FlowContents::nextNonWhitespacePosition(unsigned position, unsigned&amp; spaceCount) const
-{
-    String string = m_lineBreakIterator.string();
-    unsigned length = string.length();
-    const LChar* text = string.characters8();
-    for (; position &lt; length; ++position) {
-        bool isSpace = text[position] == ' ';
-        if (!(isSpace || text[position] == '\t' || (!m_style.preserveNewline &amp;&amp; text[position] == '\n')))
-            return position;
-        if (isSpace)
-            ++spaceCount;
-    }
-    return length;
-}
-
-float FlowContents::runWidth(const RenderText&amp; renderer, unsigned from, unsigned to, float xPosition) const
-{
</del><span class="cx">     ASSERT(from &lt; to);
</span><del>-    String string = renderer.text();
-    bool measureWithEndSpace = m_style.collapseWhitespace &amp;&amp; to &lt; string.length() &amp;&amp; string[to] == ' ';
</del><ins>+    bool measureWithEndSpace = m_style.collapseWhitespace &amp;&amp; to &lt; text.length() &amp;&amp; text[to] == ' ';
</ins><span class="cx">     if (measureWithEndSpace)
</span><span class="cx">         ++to;
</span><del>-    TextRun run(string.characters8() + from, to - from);
</del><ins>+    TextRun run(text.characters8() + from, to - from);
</ins><span class="cx">     run.setXPos(xPosition);
</span><span class="cx">     run.setTabSize(!!m_style.tabWidth, m_style.tabWidth);
</span><span class="cx">     float width = m_style.font.width(run);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingSimpleLineLayoutFlowContentsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h (176527 => 176528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h        2014-11-25 00:10:17 UTC (rev 176527)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFlowContents.h        2014-11-25 00:15:46 UTC (rev 176528)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx">     struct Segment {
</span><span class="cx">         unsigned start;
</span><span class="cx">         unsigned end;
</span><ins>+        String text;
</ins><span class="cx">         const RenderText&amp; renderer;
</span><span class="cx">     };
</span><span class="cx">     const Segment&amp; segmentForPosition(unsigned) const;
</span><span class="lines">@@ -75,11 +76,12 @@
</span><span class="cx">     const Style&amp; style() const { return m_style; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    const Segment&amp; segmentForPositionSlow(unsigned) const;
-    bool appendNextRendererContentIfNeeded(unsigned position) const;
-    unsigned nextNonWhitespacePosition(unsigned position, unsigned&amp; spaceCount) const;
-    float runWidth(const RenderText&amp;, unsigned from, unsigned to, float xPosition) const;
</del><ins>+    unsigned segmentIndexForPosition(unsigned position) const;
+    unsigned segmentIndexForPositionSlow(unsigned position) const;
</ins><span class="cx"> 
</span><ins>+    UChar characterAt(unsigned position) const;
+    float runWidth(const String&amp;, unsigned from, unsigned to, float xPosition) const;
+
</ins><span class="cx">     const Style m_style;
</span><span class="cx">     const Vector&lt;Segment, 8&gt; m_segments;
</span><span class="cx"> 
</span><span class="lines">@@ -87,11 +89,15 @@
</span><span class="cx">     mutable unsigned m_lastSegmentIndex;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+inline UChar FlowContents::characterAt(unsigned position) const
+{
+    auto&amp; segment = segmentForPosition(position);
+    return segment.text[position - segment.start];
+}
+
</ins><span class="cx"> inline bool FlowContents::isNewlineCharacter(unsigned position) const
</span><span class="cx"> {
</span><del>-    appendNextRendererContentIfNeeded(position);
-    ASSERT(position &lt; m_lineBreakIterator.string().length());
-    return m_lineBreakIterator.string().at(position) == '\n';
</del><ins>+    return characterAt(position) == '\n';
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> inline bool FlowContents::isEnd(unsigned position) const
</span><span class="lines">@@ -99,17 +105,21 @@
</span><span class="cx">     return position &gt;= length();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline const FlowContents::Segment&amp; FlowContents::segmentForPosition(unsigned position) const
</del><ins>+inline unsigned FlowContents::segmentIndexForPosition(unsigned position) const
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(!isEnd(position));
</span><del>-
</del><span class="cx">     auto&amp; lastSegment = m_segments[m_lastSegmentIndex];
</span><span class="cx">     if (lastSegment.start &lt;= position &amp;&amp; position &lt; lastSegment.end)
</span><del>-        return lastSegment;
-    return segmentForPositionSlow(position);
</del><ins>+        return m_lastSegmentIndex;
+    return segmentIndexForPositionSlow(position);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline const FlowContents::Segment&amp; FlowContents::segmentForPosition(unsigned position) const
+{
+    return m_segments[segmentIndexForPosition(position)];
</ins><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>