<!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>[170561] 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/170561">170561</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2014-06-27 16:32:51 -0700 (Fri, 27 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Remove BufferForAppendingHyphen
https://bugs.webkit.org/show_bug.cgi?id=134376

Reviewed by Darin Adler.

It is legacy, from a time when that code was using a Vector.

The problem is that StringBuilder's memory was also implicitly used to keep
the string alive for the lifespan of the TextRun. That seems quite dangerous
as changes in StringBuilder could have changed that.

To fix the lifetime issue, my first idea was to make it explicit by passing
a String reference to hold the memory alive, and a boolean to say if the text
need an hyphen. The problem with that is this code is very hot and I made things
worse.

The solution with this patch is to just pass a pointer to a String to do both
the buffer reference, and the decision to add the hyphen. Having a single
argument with 2 meanings is not pretty but that's not worse than the old buffer.

* editing/TextIterator.cpp:
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::localSelectionRect):
(WebCore::InlineTextBox::paint):
(WebCore::InlineTextBox::paintSelection):
(WebCore::InlineTextBox::constructTextRun):
(WebCore::adjustCharactersAndLengthForHyphen): Deleted.
* rendering/InlineTextBox.h:
(WebCore::BufferForAppendingHyphen::BufferForAppendingHyphen): Deleted.
* rendering/RenderText.cpp:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreeditingTextIteratorcpp">trunk/Source/WebCore/editing/TextIterator.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingInlineTextBoxcpp">trunk/Source/WebCore/rendering/InlineTextBox.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingInlineTextBoxh">trunk/Source/WebCore/rendering/InlineTextBox.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderTextcpp">trunk/Source/WebCore/rendering/RenderText.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (170560 => 170561)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-06-27 23:28:35 UTC (rev 170560)
+++ trunk/Source/WebCore/ChangeLog        2014-06-27 23:32:51 UTC (rev 170561)
</span><span class="lines">@@ -1,3 +1,36 @@
</span><ins>+2014-06-27  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
+        Remove BufferForAppendingHyphen
+        https://bugs.webkit.org/show_bug.cgi?id=134376
+
+        Reviewed by Darin Adler.
+
+        It is legacy, from a time when that code was using a Vector.
+
+        The problem is that StringBuilder's memory was also implicitly used to keep
+        the string alive for the lifespan of the TextRun. That seems quite dangerous
+        as changes in StringBuilder could have changed that.
+
+        To fix the lifetime issue, my first idea was to make it explicit by passing
+        a String reference to hold the memory alive, and a boolean to say if the text
+        need an hyphen. The problem with that is this code is very hot and I made things
+        worse.
+
+        The solution with this patch is to just pass a pointer to a String to do both
+        the buffer reference, and the decision to add the hyphen. Having a single
+        argument with 2 meanings is not pretty but that's not worse than the old buffer.
+
+        * editing/TextIterator.cpp:
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::localSelectionRect):
+        (WebCore::InlineTextBox::paint):
+        (WebCore::InlineTextBox::paintSelection):
+        (WebCore::InlineTextBox::constructTextRun):
+        (WebCore::adjustCharactersAndLengthForHyphen): Deleted.
+        * rendering/InlineTextBox.h:
+        (WebCore::BufferForAppendingHyphen::BufferForAppendingHyphen): Deleted.
+        * rendering/RenderText.cpp:
+
</ins><span class="cx"> 2014-06-27  Jeremy Jones  &lt;jeremyj@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Lazily link frameworks in WebVideoFullscreenInterfaceAVKit.
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingTextIteratorcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/TextIterator.cpp (170560 => 170561)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/TextIterator.cpp        2014-06-27 23:28:35 UTC (rev 170560)
+++ trunk/Source/WebCore/editing/TextIterator.cpp        2014-06-27 23:32:51 UTC (rev 170561)
</span><span class="lines">@@ -50,6 +50,7 @@
</span><span class="cx"> #include &quot;VisibleUnits.h&quot;
</span><span class="cx"> #include &quot;htmlediting.h&quot;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><ins>+#include &lt;wtf/text/StringBuilder.h&gt;
</ins><span class="cx"> #include &lt;wtf/unicode/CharacterNames.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if !UCONFIG_NO_COLLATION
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingInlineTextBoxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (170560 => 170561)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/InlineTextBox.cpp        2014-06-27 23:28:35 UTC (rev 170560)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp        2014-06-27 23:32:51 UTC (rev 170561)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  * (C) 1999 Lars Knoll (knoll@kde.org)
</span><span class="cx">  * (C) 2000 Dirk Mueller (mueller@kde.org)
</span><del>- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2004-2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * This library is free software; you can redistribute it and/or
</span><span class="cx">  * modify it under the terms of the GNU Library General Public
</span><span class="lines">@@ -251,16 +251,6 @@
</span><span class="cx">     return state;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void adjustCharactersAndLengthForHyphen(BufferForAppendingHyphen&amp; charactersWithHyphen, const RenderStyle&amp; style, String&amp; string, unsigned&amp; length)
-{
-    const AtomicString&amp; hyphenString = style.hyphenString();
-    charactersWithHyphen.reserveCapacity(length + hyphenString.length());
-    charactersWithHyphen.append(string);
-    charactersWithHyphen.append(hyphenString);
-    string = charactersWithHyphen.toString();
-    length += hyphenString.length();
-}
-
</del><span class="cx"> static const Font&amp; fontToUse(const RenderStyle&amp; style, const RenderText&amp; renderer)
</span><span class="cx"> {
</span><span class="cx">     if (style.hasTextCombine() &amp;&amp; renderer.isCombineText()) {
</span><span class="lines">@@ -290,9 +280,9 @@
</span><span class="cx">     const RenderStyle&amp; lineStyle = this-&gt;lineStyle();
</span><span class="cx">     const Font&amp; font = fontToUse(lineStyle, renderer());
</span><span class="cx"> 
</span><del>-    BufferForAppendingHyphen charactersWithHyphen;
</del><ins>+    String hyphenatedStringBuffer;
</ins><span class="cx">     bool respectHyphen = ePos == m_len &amp;&amp; hasHyphen();
</span><del>-    TextRun textRun = constructTextRun(lineStyle, font, respectHyphen ? &amp;charactersWithHyphen : 0);
</del><ins>+    TextRun textRun = constructTextRun(lineStyle, font, respectHyphen ? &amp;hyphenatedStringBuffer : 0);
</ins><span class="cx"> 
</span><span class="cx">     LayoutRect selectionRect = LayoutRect(LayoutPoint(logicalLeft(), selectionTop), LayoutSize(m_logicalWidth, selectionHeight));
</span><span class="cx">     // Avoid computing the font width when the entire line box is selected as an optimization.
</span><span class="lines">@@ -629,8 +619,8 @@
</span><span class="cx">         maximumLength = length;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    BufferForAppendingHyphen charactersWithHyphen;
-    TextRun textRun = constructTextRun(lineStyle, font, string, maximumLength, hasHyphen() ? &amp;charactersWithHyphen : 0);
</del><ins>+    String hyphenatedStringBuffer;
+    TextRun textRun = constructTextRun(lineStyle, font, string, maximumLength, hasHyphen() ? &amp;hyphenatedStringBuffer : nullptr);
</ins><span class="cx">     if (hasHyphen())
</span><span class="cx">         length = textRun.length();
</span><span class="cx"> 
</span><span class="lines">@@ -758,10 +748,10 @@
</span><span class="cx">         string = string.substringSharingImpl(m_start, length);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    BufferForAppendingHyphen charactersWithHyphen;
-    bool respectHyphen = ePos == length &amp;&amp; hasHyphen();
</del><span class="cx">     ASSERT(renderer().textLength() &gt;= m_start);
</span><del>-    TextRun textRun = constructTextRun(style, font, string, renderer().textLength() - m_start, respectHyphen ? &amp;charactersWithHyphen : 0);
</del><ins>+    String hyphenatedStringBuffer;
+    bool respectHyphen = ePos == length &amp;&amp; hasHyphen();
+    TextRun textRun = constructTextRun(style, font, string, renderer().textLength() - m_start, respectHyphen ? &amp;hyphenatedStringBuffer : nullptr);
</ins><span class="cx">     if (respectHyphen)
</span><span class="cx">         ePos = textRun.length();
</span><span class="cx"> 
</span><span class="lines">@@ -1418,7 +1408,7 @@
</span><span class="cx">     return directionalPixelSnappedForPainting(selectionRect, renderer().document().deviceScaleFactor(), run.ltr()).maxX();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-TextRun InlineTextBox::constructTextRun(const RenderStyle&amp; style, const Font&amp; font, BufferForAppendingHyphen* charactersWithHyphen) const
</del><ins>+TextRun InlineTextBox::constructTextRun(const RenderStyle&amp; style, const Font&amp; font, String* hyphenatedStringBuffer) const
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(renderer().text());
</span><span class="cx"> 
</span><span class="lines">@@ -1430,16 +1420,18 @@
</span><span class="cx">         string = string.substringSharingImpl(startPos, length);
</span><span class="cx">     
</span><span class="cx">     ASSERT(renderer().textLength() &gt;= startPos);
</span><del>-    return constructTextRun(style, font, string, renderer().textLength() - startPos, charactersWithHyphen);
</del><ins>+    return constructTextRun(style, font, string, renderer().textLength() - startPos, hyphenatedStringBuffer);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-TextRun InlineTextBox::constructTextRun(const RenderStyle&amp; style, const Font&amp; font, String string, unsigned maximumLength, BufferForAppendingHyphen* charactersWithHyphen) const
</del><ins>+TextRun InlineTextBox::constructTextRun(const RenderStyle&amp; style, const Font&amp; font, String string, unsigned maximumLength, String* hyphenatedStringBuffer) const
</ins><span class="cx"> {
</span><span class="cx">     unsigned length = string.length();
</span><span class="cx"> 
</span><del>-    if (charactersWithHyphen) {
-        adjustCharactersAndLengthForHyphen(*charactersWithHyphen, style, string, length);
-        maximumLength = length;
</del><ins>+    if (hyphenatedStringBuffer) {
+        const AtomicString&amp; hyphenString = style.hyphenString();
+        *hyphenatedStringBuffer = string + hyphenString;
+        string = *hyphenatedStringBuffer;
+        maximumLength = length + hyphenString.length();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT(maximumLength &gt;= length);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingInlineTextBoxh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/InlineTextBox.h (170560 => 170561)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/InlineTextBox.h        2014-06-27 23:28:35 UTC (rev 170560)
+++ trunk/Source/WebCore/rendering/InlineTextBox.h        2014-06-27 23:32:51 UTC (rev 170561)
</span><span class="lines">@@ -1,7 +1,7 @@
</span><span class="cx"> /*
</span><span class="cx">  * (C) 1999 Lars Knoll (knoll@kde.org)
</span><span class="cx">  * (C) 2000 Dirk Mueller (mueller@kde.org)
</span><del>- * Copyright (C) 2004, 2005, 2006, 2009, 2010, 2011 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2004, 2005, 2006, 2009, 2010, 2011, 2014 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * This library is free software; you can redistribute it and/or
</span><span class="cx">  * modify it under the terms of the GNU Library General Public
</span><span class="lines">@@ -26,7 +26,6 @@
</span><span class="cx"> #include &quot;InlineBox.h&quot;
</span><span class="cx"> #include &quot;RenderText.h&quot;
</span><span class="cx"> #include &quot;TextRun.h&quot;
</span><del>-#include &lt;wtf/text/StringBuilder.h&gt;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -37,11 +36,6 @@
</span><span class="cx"> const unsigned cNoTruncation = std::numeric_limits&lt;unsigned&gt;::max();
</span><span class="cx"> const unsigned cFullTruncation = std::numeric_limits&lt;unsigned&gt;::max() - 1;
</span><span class="cx"> 
</span><del>-class BufferForAppendingHyphen : public StringBuilder {
-public:
-    BufferForAppendingHyphen() { reserveCapacity(256); }
-};
-
</del><span class="cx"> class InlineTextBox : public InlineBox {
</span><span class="cx"> public:
</span><span class="cx">     explicit InlineTextBox(RenderText&amp; renderer)
</span><span class="lines">@@ -110,8 +104,8 @@
</span><span class="cx">     LayoutUnit selectionBottom() const;
</span><span class="cx">     LayoutUnit selectionHeight() const;
</span><span class="cx"> 
</span><del>-    TextRun constructTextRun(const RenderStyle&amp;, const Font&amp;, BufferForAppendingHyphen* = nullptr) const;
-    TextRun constructTextRun(const RenderStyle&amp;, const Font&amp;, String, unsigned maximumLength, BufferForAppendingHyphen* = nullptr) const;
</del><ins>+    TextRun constructTextRun(const RenderStyle&amp;, const Font&amp;, String* hyphenatedStringBuffer = nullptr) const;
+    TextRun constructTextRun(const RenderStyle&amp;, const Font&amp;, String, unsigned maximumLength, String* hyphenatedStringBuffer = nullptr) const;
</ins><span class="cx"> 
</span><span class="cx"> public:
</span><span class="cx">     virtual FloatRect calculateBoundaries() const { return FloatRect(x(), y(), width(), height()); }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderTextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderText.cpp (170560 => 170561)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderText.cpp        2014-06-27 23:28:35 UTC (rev 170560)
+++ trunk/Source/WebCore/rendering/RenderText.cpp        2014-06-27 23:32:51 UTC (rev 170561)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx"> #include &quot;break_lines.h&quot;
</span><span class="cx"> #include &lt;wtf/NeverDestroyed.h&gt;
</span><span class="cx"> #include &lt;wtf/text/StringBuffer.h&gt;
</span><ins>+#include &lt;wtf/text/StringBuilder.h&gt;
</ins><span class="cx"> #include &lt;wtf/unicode/CharacterNames.h&gt;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre>
</div>
</div>

</body>
</html>