<!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>[174228] 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/174228">174228</a></dd>
<dt>Author</dt> <dd>mmaxfield@apple.com</dd>
<dt>Date</dt> <dd>2014-10-02 13:54:21 -0700 (Thu, 02 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Back TextRun with a StringView
https://bugs.webkit.org/show_bug.cgi?id=137352

Reviewed by Antti Koivisto.

TextRun contains a union of a UChar* and an LChar* as well as a length, which is the abstraction
that StringView is intended to be. This patch cleans up TextRun by replacing the union and length
with a StringView instance member.

No new tests because there is no behavior change.

* platform/graphics/TextRun.h:
(WebCore::TextRun::TextRun):
(WebCore::TextRun::subRun):
(WebCore::TextRun::operator[]):
(WebCore::TextRun::data8):
(WebCore::TextRun::data16):
(WebCore::TextRun::characters8):
(WebCore::TextRun::characters16):
(WebCore::TextRun::is8Bit):
(WebCore::TextRun::length):
(WebCore::TextRun::string):
(WebCore::TextRun::setText):
(WebCore::TextRun::stringView):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsTextRunh">trunk/Source/WebCore/platform/graphics/TextRun.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (174227 => 174228)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-10-02 20:50:08 UTC (rev 174227)
+++ trunk/Source/WebCore/ChangeLog        2014-10-02 20:54:21 UTC (rev 174228)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-10-02  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
+
+        Back TextRun with a StringView
+        https://bugs.webkit.org/show_bug.cgi?id=137352
+
+        Reviewed by Antti Koivisto.
+
+        TextRun contains a union of a UChar* and an LChar* as well as a length, which is the abstraction
+        that StringView is intended to be. This patch cleans up TextRun by replacing the union and length
+        with a StringView instance member.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/TextRun.h:
+        (WebCore::TextRun::TextRun):
+        (WebCore::TextRun::subRun):
+        (WebCore::TextRun::operator[]):
+        (WebCore::TextRun::data8):
+        (WebCore::TextRun::data16):
+        (WebCore::TextRun::characters8):
+        (WebCore::TextRun::characters16):
+        (WebCore::TextRun::is8Bit):
+        (WebCore::TextRun::length):
+        (WebCore::TextRun::string):
+        (WebCore::TextRun::setText):
+        (WebCore::TextRun::stringView):
+
</ins><span class="cx"> 2014-10-01  Christophe Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Have is&lt;&gt;(T*) function do a null check on the pointer argument
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsTextRunh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/TextRun.h (174227 => 174228)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/TextRun.h        2014-10-02 20:50:08 UTC (rev 174227)
+++ trunk/Source/WebCore/platform/graphics/TextRun.h        2014-10-02 20:54:21 UTC (rev 174228)
</span><span class="lines">@@ -62,14 +62,13 @@
</span><span class="cx">     typedef unsigned RoundingHacks;
</span><span class="cx"> 
</span><span class="cx">     TextRun(const LChar* c, unsigned len, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
</span><del>-        : m_charactersLength(len)
-        , m_len(len)
</del><ins>+        : m_text(c, len)
+        , m_charactersLength(len)
</ins><span class="cx">         , m_tabSize(0)
</span><span class="cx">         , m_xpos(xpos)
</span><span class="cx">         , m_horizontalGlyphStretch(1)
</span><span class="cx">         , m_expansion(expansion)
</span><span class="cx">         , m_expansionBehavior(expansionBehavior)
</span><del>-        , m_is8Bit(true)
</del><span class="cx">         , m_allowTabs(false)
</span><span class="cx">         , m_direction(direction)
</span><span class="cx">         , m_directionalOverride(directionalOverride)
</span><span class="lines">@@ -78,18 +77,16 @@
</span><span class="cx">         , m_applyWordRounding((roundingHacks &amp; WordRounding) &amp;&amp; s_allowsRoundingHacks)
</span><span class="cx">         , m_disableSpacing(false)
</span><span class="cx">     {
</span><del>-        m_data.characters8 = c;
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     TextRun(const UChar* c, unsigned len, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
</span><del>-        : m_charactersLength(len)
-        , m_len(len)
</del><ins>+        : m_text(c, len)
+        , m_charactersLength(len)
</ins><span class="cx">         , m_tabSize(0)
</span><span class="cx">         , m_xpos(xpos)
</span><span class="cx">         , m_horizontalGlyphStretch(1)
</span><span class="cx">         , m_expansion(expansion)
</span><span class="cx">         , m_expansionBehavior(expansionBehavior)
</span><del>-        , m_is8Bit(false)
</del><span class="cx">         , m_allowTabs(false)
</span><span class="cx">         , m_direction(direction)
</span><span class="cx">         , m_directionalOverride(directionalOverride)
</span><span class="lines">@@ -98,12 +95,11 @@
</span><span class="cx">         , m_applyWordRounding((roundingHacks &amp; WordRounding) &amp;&amp; s_allowsRoundingHacks)
</span><span class="cx">         , m_disableSpacing(false)
</span><span class="cx">     {
</span><del>-        m_data.characters16 = c;
</del><span class="cx">     }
</span><span class="cx">     
</span><span class="cx">     explicit TextRun(const String&amp; s, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
</span><del>-        : m_charactersLength(s.length())
-        , m_len(s.length())
</del><ins>+        : m_text(StringView(s))
+        , m_charactersLength(s.length())
</ins><span class="cx">         , m_tabSize(0)
</span><span class="cx">         , m_xpos(xpos)
</span><span class="cx">         , m_horizontalGlyphStretch(1)
</span><span class="lines">@@ -117,24 +113,16 @@
</span><span class="cx">         , m_applyWordRounding((roundingHacks &amp; WordRounding) &amp;&amp; s_allowsRoundingHacks)
</span><span class="cx">         , m_disableSpacing(false)
</span><span class="cx">     {
</span><del>-        if (!m_charactersLength || s.is8Bit()) {
-            m_data.characters8 = s.characters8();
-            m_is8Bit = true;
-        } else {
-            m_data.characters16 = s.characters16();
-            m_is8Bit = false;
-        }
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     explicit TextRun(StringView s, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding)
</span><del>-        : m_charactersLength(s.length())
-        , m_len(s.length())
</del><ins>+        : m_text(s)
+        , m_charactersLength(s.length())
</ins><span class="cx">         , m_tabSize(0)
</span><span class="cx">         , m_xpos(xpos)
</span><span class="cx">         , m_horizontalGlyphStretch(1)
</span><span class="cx">         , m_expansion(expansion)
</span><span class="cx">         , m_expansionBehavior(expansionBehavior)
</span><del>-        , m_is8Bit(s.is8Bit())
</del><span class="cx">         , m_allowTabs(false)
</span><span class="cx">         , m_direction(direction)
</span><span class="cx">         , m_directionalOverride(directionalOverride)
</span><span class="lines">@@ -143,15 +131,11 @@
</span><span class="cx">         , m_applyWordRounding((roundingHacks &amp; WordRounding) &amp;&amp; s_allowsRoundingHacks)
</span><span class="cx">         , m_disableSpacing(false)
</span><span class="cx">     {
</span><del>-        if (s.is8Bit())
-            m_data.characters8 = s.characters8();
-        else
-            m_data.characters16 = s.characters16();
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     TextRun subRun(unsigned startOffset, unsigned length) const
</span><span class="cx">     {
</span><del>-        ASSERT_WITH_SECURITY_IMPLICATION(startOffset &lt; m_len);
</del><ins>+        ASSERT_WITH_SECURITY_IMPLICATION(startOffset &lt; m_text.length());
</ins><span class="cx"> 
</span><span class="cx">         TextRun result = *this;
</span><span class="cx"> 
</span><span class="lines">@@ -163,26 +147,21 @@
</span><span class="cx">         return result;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    UChar operator[](unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i &lt; m_len); return is8Bit() ? m_data.characters8[i] :m_data.characters16[i]; }
-    const LChar* data8(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i &lt; m_len); ASSERT(is8Bit()); return &amp;m_data.characters8[i]; }
-    const UChar* data16(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i &lt; m_len); ASSERT(!is8Bit()); return &amp;m_data.characters16[i]; }
</del><ins>+    UChar operator[](unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i &lt; m_text.length()); return m_text[i]; }
+    const LChar* data8(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i &lt; m_text.length()); ASSERT(is8Bit()); return &amp;m_text.characters8()[i]; }
+    const UChar* data16(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i &lt; m_text.length()); ASSERT(!is8Bit()); return &amp;m_text.characters16()[i]; }
</ins><span class="cx"> 
</span><del>-    const LChar* characters8() const { ASSERT(is8Bit()); return m_data.characters8; }
-    const UChar* characters16() const { ASSERT(!is8Bit()); return m_data.characters16; }
</del><ins>+    const LChar* characters8() const { ASSERT(is8Bit()); return m_text.characters8(); }
+    const UChar* characters16() const { ASSERT(!is8Bit()); return m_text.characters16(); }
</ins><span class="cx">     
</span><del>-    bool is8Bit() const { return m_is8Bit; }
-    int length() const { return m_len; }
</del><ins>+    bool is8Bit() const { return m_text.is8Bit(); }
+    int length() const { return m_text.length(); }
</ins><span class="cx">     int charactersLength() const { return m_charactersLength; }
</span><del>-    String string() const
-    {
-        if (is8Bit())
-            return String(m_data.characters8, m_len);
-        return String(m_data.characters16, m_len);
-    }
</del><ins>+    String string() const { return m_text.toString(); }
</ins><span class="cx"> 
</span><del>-    void setText(const LChar* c, unsigned len) { m_data.characters8 = c; m_len = len; m_is8Bit = true;}
-    void setText(const UChar* c, unsigned len) { m_data.characters16 = c; m_len = len; m_is8Bit = false;}
-    void setText(StringView);
</del><ins>+    void setText(const LChar* c, unsigned len) { m_text = StringView(c, len); }
+    void setText(const UChar* c, unsigned len) { m_text = StringView(c, len); }
+    void setText(StringView stringView) { m_text = stringView; }
</ins><span class="cx">     void setCharactersLength(unsigned charactersLength) { m_charactersLength = charactersLength; }
</span><span class="cx"> 
</span><span class="cx">     float horizontalGlyphStretch() const { return m_horizontalGlyphStretch; }
</span><span class="lines">@@ -211,6 +190,7 @@
</span><span class="cx">     void setDirection(TextDirection direction) { m_direction = direction; }
</span><span class="cx">     void setDirectionalOverride(bool override) { m_directionalOverride = override; }
</span><span class="cx">     void setCharacterScanForCodePath(bool scan) { m_characterScanForCodePath = scan; }
</span><ins>+    StringView text() const { return m_text; }
</ins><span class="cx"> 
</span><span class="cx">     class RenderingContext : public RefCounted&lt;RenderingContext&gt; {
</span><span class="cx">     public:
</span><span class="lines">@@ -233,16 +213,11 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     static bool s_allowsRoundingHacks;
</span><del>-
-    union {
-        const LChar* characters8;
-        const UChar* characters16;
-    } m_data;
-
</del><ins>+    
</ins><span class="cx">     RefPtr&lt;RenderingContext&gt; m_renderingContext;
</span><span class="cx"> 
</span><del>-    unsigned m_charactersLength; // Marks the end of the characters buffer. Default equals to m_len.
-    unsigned m_len;
</del><ins>+    StringView m_text;
+    unsigned m_charactersLength; // Marks the end of the characters buffer. Default equals to length of m_text.
</ins><span class="cx"> 
</span><span class="cx">     unsigned m_tabSize;
</span><span class="cx"> 
</span><span class="lines">@@ -254,7 +229,6 @@
</span><span class="cx"> 
</span><span class="cx">     float m_expansion;
</span><span class="cx">     ExpansionBehavior m_expansionBehavior : 2;
</span><del>-    unsigned m_is8Bit : 1;
</del><span class="cx">     unsigned m_allowTabs : 1;
</span><span class="cx">     unsigned m_direction : 1;
</span><span class="cx">     unsigned m_directionalOverride : 1; // Was this direction set by an override character.
</span><span class="lines">@@ -270,16 +244,6 @@
</span><span class="cx">     m_tabSize = size;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline void TextRun::setText(StringView string)
-{
-    m_len = string.length();
-    m_is8Bit = string.is8Bit();
-    if (string.is8Bit())
-        m_data.characters8 = string.characters8();
-    else
-        m_data.characters16 = string.characters16();
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-}
-
</del><span class="cx"> #endif
</span></span></pre>
</div>
</div>

</body>
</html>