<!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>[174234] trunk/Source/WTF</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/174234">174234</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-10-02 15:48:48 -0700 (Thu, 02 Oct 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Simplify StringTypeAdapter templates
https://bugs.webkit.org/show_bug.cgi?id=137356

Reviewed by Andreas Kling.

* wtf/text/StringConcatenate.h:
Use StringView for copying characters. Use inheritance for char* vs const char* etc. Make all StringAdapter member functions const.

* wtf/text/StringView.h:
Move enough functions out of line so we can include WTFString.h after the StringView class definition.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtftextStringConcatenateh">trunk/Source/WTF/wtf/text/StringConcatenate.h</a></li>
<li><a href="#trunkSourceWTFwtftextStringViewh">trunk/Source/WTF/wtf/text/StringView.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (174233 => 174234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-10-02 22:25:50 UTC (rev 174233)
+++ trunk/Source/WTF/ChangeLog        2014-10-02 22:48:48 UTC (rev 174234)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2014-10-02  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Simplify StringTypeAdapter templates
+        https://bugs.webkit.org/show_bug.cgi?id=137356
+
+        Reviewed by Andreas Kling.
+
+        * wtf/text/StringConcatenate.h:
+        Use StringView for copying characters. Use inheritance for char* vs const char* etc. Make all StringAdapter member functions const.
+
+        * wtf/text/StringView.h:
+        Move enough functions out of line so we can include WTFString.h after the StringView class definition.
+
</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="trunkSourceWTFwtftextStringConcatenateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringConcatenate.h (174233 => 174234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/text/StringConcatenate.h        2014-10-02 22:25:50 UTC (rev 174233)
+++ trunk/Source/WTF/wtf/text/StringConcatenate.h        2014-10-02 22:48:48 UTC (rev 174234)
</span><span class="lines">@@ -32,6 +32,10 @@
</span><span class="cx"> #include &lt;wtf/text/AtomicString.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#ifndef StringView_h
+#include &lt;wtf/text/StringView.h&gt;
+#endif
+
</ins><span class="cx"> // This macro is helpful for testing how many intermediate Strings are created while evaluating an
</span><span class="cx"> // expression containing operator+.
</span><span class="cx"> #ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING
</span><span class="lines">@@ -41,379 +45,204 @@
</span><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><span class="cx"> template&lt;typename StringType&gt;
</span><del>-class StringTypeAdapter {
-};
</del><ins>+class StringTypeAdapter;
</ins><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><span class="cx"> class StringTypeAdapter&lt;char&gt; {
</span><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;char&gt;(char buffer)
-        : m_buffer(buffer)
</del><ins>+    StringTypeAdapter&lt;char&gt;(char character)
+        : m_character(character)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     unsigned length() { return 1; }
</span><del>-
</del><span class="cx">     bool is8Bit() { return true; }
</span><span class="cx"> 
</span><del>-    void writeTo(LChar* destination)
</del><ins>+    void writeTo(LChar* destination) const
</ins><span class="cx">     {
</span><del>-        *destination = m_buffer;
</del><ins>+        *destination = m_character;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void writeTo(UChar* destination) { *destination = m_buffer; }
-
-private:
-    unsigned char m_buffer;
-};
-
-template&lt;&gt;
-class StringTypeAdapter&lt;LChar&gt; {
-public:
-    StringTypeAdapter&lt;LChar&gt;(LChar buffer)
-        : m_buffer(buffer)
</del><ins>+    void writeTo(UChar* destination) const
</ins><span class="cx">     {
</span><ins>+        *destination = m_character;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    unsigned length() { return 1; }
-
-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
-    {
-        *destination = m_buffer;
-    }
-
-    void writeTo(UChar* destination) { *destination = m_buffer; }
-
</del><span class="cx"> private:
</span><del>-    LChar m_buffer;
</del><ins>+    char m_character;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><span class="cx"> class StringTypeAdapter&lt;UChar&gt; {
</span><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;UChar&gt;(UChar buffer)
-        : m_buffer(buffer)
</del><ins>+    StringTypeAdapter&lt;UChar&gt;(UChar character)
+        : m_character(character)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    unsigned length() { return 1; }
</del><ins>+    unsigned length() const { return 1; }
+    bool is8Bit() const { return m_character &lt;= 0xff; }
</ins><span class="cx"> 
</span><del>-    bool is8Bit() { return m_buffer &lt;= 0xff; }
-
-    void writeTo(LChar* destination)
</del><ins>+    void writeTo(LChar* destination) const
</ins><span class="cx">     {
</span><span class="cx">         ASSERT(is8Bit());
</span><del>-        *destination = static_cast&lt;LChar&gt;(m_buffer);
</del><ins>+        *destination = static_cast&lt;LChar&gt;(m_character);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void writeTo(UChar* destination) { *destination = m_buffer; }
-
-private:
-    UChar m_buffer;
-};
-
-template&lt;&gt;
-class StringTypeAdapter&lt;char*&gt; {
-public:
-    StringTypeAdapter&lt;char*&gt;(char* buffer)
-        : m_buffer(buffer)
-        , m_length(strlen(buffer))
</del><ins>+    void writeTo(UChar* destination) const
</ins><span class="cx">     {
</span><ins>+        *destination = m_character;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    unsigned length() { return m_length; }
-
-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
-    {
-        for (unsigned i = 0; i &lt; m_length; ++i)
-            destination[i] = static_cast&lt;LChar&gt;(m_buffer[i]);
-    }
-
-    void writeTo(UChar* destination)
-    {
-        for (unsigned i = 0; i &lt; m_length; ++i) {
-            unsigned char c = m_buffer[i];
-            destination[i] = c;
-        }
-    }
-
</del><span class="cx"> private:
</span><del>-    const char* m_buffer;
-    unsigned m_length;
</del><ins>+    UChar m_character;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><del>-class StringTypeAdapter&lt;LChar*&gt; {
</del><ins>+class StringTypeAdapter&lt;const LChar*&gt; {
</ins><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;LChar*&gt;(LChar* buffer)
-    : m_buffer(buffer)
-    , m_length(strlen(reinterpret_cast&lt;char*&gt;(buffer)))
</del><ins>+    StringTypeAdapter(const LChar* characters)
+        : m_characters(characters)
+        , m_length(strlen(reinterpret_cast&lt;const char*&gt;(characters)))
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    unsigned length() { return m_length; }
</del><ins>+    unsigned length() const { return m_length; }
+    bool is8Bit() const { return true; }
</ins><span class="cx"> 
</span><del>-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
</del><ins>+    void writeTo(LChar* destination) const
</ins><span class="cx">     {
</span><del>-        memcpy(destination, m_buffer, m_length * sizeof(LChar));
</del><ins>+        StringView(m_characters, m_length).getCharactersWithUpconvert(destination);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void writeTo(UChar* destination)
</del><ins>+    void writeTo(UChar* destination) const
</ins><span class="cx">     {
</span><del>-        StringImpl::copyChars(destination, m_buffer, m_length);
</del><ins>+        StringView(m_characters, m_length).getCharactersWithUpconvert(destination);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    const LChar* m_buffer;
</del><ins>+    const LChar* m_characters;
</ins><span class="cx">     unsigned m_length;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><span class="cx"> class StringTypeAdapter&lt;const UChar*&gt; {
</span><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;const UChar*&gt;(const UChar* buffer)
-        : m_buffer(buffer)
</del><ins>+    StringTypeAdapter(const UChar* characters)
+        : m_characters(characters)
</ins><span class="cx">     {
</span><del>-        size_t len = 0;
-        while (m_buffer[len] != UChar(0))
-            ++len;
</del><ins>+        unsigned length = 0;
+        while (m_characters[length])
+            ++length;
</ins><span class="cx"> 
</span><del>-        if (len &gt; std::numeric_limits&lt;unsigned&gt;::max())
</del><ins>+        if (length &gt; std::numeric_limits&lt;unsigned&gt;::max())
</ins><span class="cx">             CRASH();
</span><span class="cx"> 
</span><del>-        m_length = len;
</del><ins>+        m_length = length;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    unsigned length() { return m_length; }
</del><ins>+    unsigned length() const { return m_length; }
+    bool is8Bit() const { return false; }
</ins><span class="cx"> 
</span><del>-    bool is8Bit() { return false; }
-
-    NO_RETURN_DUE_TO_CRASH void writeTo(LChar*)
</del><ins>+    NO_RETURN_DUE_TO_CRASH void writeTo(LChar*) const
</ins><span class="cx">     {
</span><span class="cx">         CRASH();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void writeTo(UChar* destination)
</del><ins>+    void writeTo(UChar* destination) const
</ins><span class="cx">     {
</span><del>-        memcpy(destination, m_buffer, m_length * sizeof(UChar));
</del><ins>+        memcpy(destination, m_characters, m_length * sizeof(UChar));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    const UChar* m_buffer;
</del><ins>+    const UChar* m_characters;
</ins><span class="cx">     unsigned m_length;
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><del>-class StringTypeAdapter&lt;const char*&gt; {
</del><ins>+class StringTypeAdapter&lt;const char*&gt; : public StringTypeAdapter&lt;const LChar*&gt; {
</ins><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;const char*&gt;(const char* buffer)
-        : m_buffer(buffer)
-        , m_length(strlen(buffer))
</del><ins>+    StringTypeAdapter(const char* characters)
+        : StringTypeAdapter&lt;const LChar*&gt;(reinterpret_cast&lt;const LChar*&gt;(characters))
</ins><span class="cx">     {
</span><span class="cx">     }
</span><del>-
-    unsigned length() { return m_length; }
-
-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
-    {
-        memcpy(destination, m_buffer, static_cast&lt;size_t&gt;(m_length) * sizeof(LChar));
-    }
-
-    void writeTo(UChar* destination)
-    {
-        for (unsigned i = 0; i &lt; m_length; ++i) {
-            unsigned char c = m_buffer[i];
-            destination[i] = c;
-        }
-    }
-
-private:
-    const char* m_buffer;
-    unsigned m_length;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><del>-class StringTypeAdapter&lt;const LChar*&gt; {
</del><ins>+class StringTypeAdapter&lt;char*&gt; : public StringTypeAdapter&lt;const char*&gt; {
</ins><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;const LChar*&gt;(const LChar* buffer)
-        : m_buffer(buffer)
-        , m_length(strlen(reinterpret_cast&lt;const char*&gt;(buffer)))
</del><ins>+    StringTypeAdapter(const char* characters)
+        : StringTypeAdapter&lt;const char*&gt;(characters)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><del>-
-    unsigned length() { return m_length; }
-
-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
-    {
-        memcpy(destination, m_buffer, static_cast&lt;size_t&gt;(m_length) * sizeof(LChar));
-    }
-
-    void writeTo(UChar* destination)
-    {
-        StringImpl::copyChars(destination, m_buffer, m_length);
-    }
-
-private:
-    const LChar* m_buffer;
-    unsigned m_length;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><del>-class StringTypeAdapter&lt;ASCIILiteral&gt; {
</del><ins>+class StringTypeAdapter&lt;ASCIILiteral&gt; : public StringTypeAdapter&lt;const char*&gt; {
</ins><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;ASCIILiteral&gt;(ASCIILiteral buffer)
-        : m_buffer(reinterpret_cast&lt;const LChar*&gt;(static_cast&lt;const char*&gt;(buffer)))
-        , m_length(strlen(buffer))
</del><ins>+    StringTypeAdapter(ASCIILiteral characters)
+        : StringTypeAdapter&lt;const char*&gt;(characters)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><del>-
-    size_t length() { return m_length; }
-
-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
-    {
-        memcpy(destination, m_buffer, static_cast&lt;size_t&gt;(m_length));
-    }
-
-    void writeTo(UChar* destination)
-    {
-        StringImpl::copyChars(destination, m_buffer, m_length);
-    }
-
-private:
-    const LChar* m_buffer;
-    unsigned m_length;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><span class="cx"> class StringTypeAdapter&lt;Vector&lt;char&gt;&gt; {
</span><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;Vector&lt;char&gt;&gt;(const Vector&lt;char&gt;&amp; buffer)
-        : m_buffer(buffer)
</del><ins>+    StringTypeAdapter(const Vector&lt;char&gt;&amp; vector)
+        : m_vector(vector)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    size_t length() { return m_buffer.size(); }
</del><ins>+    size_t length() const { return m_vector.size(); }
+    bool is8Bit() const { return true; }
</ins><span class="cx"> 
</span><del>-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
</del><ins>+    void writeTo(LChar* destination) const
</ins><span class="cx">     {
</span><del>-        for (size_t i = 0; i &lt; m_buffer.size(); ++i)
-            destination[i] = static_cast&lt;unsigned char&gt;(m_buffer[i]);
</del><ins>+        StringView(reinterpret_cast&lt;const LChar*&gt;(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void writeTo(UChar* destination)
</del><ins>+    void writeTo(UChar* destination) const
</ins><span class="cx">     {
</span><del>-        for (size_t i = 0; i &lt; m_buffer.size(); ++i)
-            destination[i] = static_cast&lt;unsigned char&gt;(m_buffer[i]);
</del><ins>+        StringView(reinterpret_cast&lt;const LChar*&gt;(m_vector.data()), m_vector.size()).getCharactersWithUpconvert(destination);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    const Vector&lt;char&gt;&amp; m_buffer;
</del><ins>+    const Vector&lt;char&gt;&amp; m_vector;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><del>-class StringTypeAdapter&lt;Vector&lt;LChar&gt;&gt; {
-public:
-    StringTypeAdapter&lt;Vector&lt;LChar&gt;&gt;(const Vector&lt;LChar&gt;&amp; buffer)
-        : m_buffer(buffer)
-    {
-    }
-
-    size_t length() { return m_buffer.size(); }
-
-    bool is8Bit() { return true; }
-
-    void writeTo(LChar* destination)
-    {
-        for (size_t i = 0; i &lt; m_buffer.size(); ++i)
-            destination[i] = m_buffer[i];
-    }
-
-    void writeTo(UChar* destination)
-    {
-        for (size_t i = 0; i &lt; m_buffer.size(); ++i)
-            destination[i] = m_buffer[i];
-    }
-
-private:
-    const Vector&lt;LChar&gt;&amp; m_buffer;
-};
-
-template&lt;&gt;
</del><span class="cx"> class StringTypeAdapter&lt;String&gt; {
</span><span class="cx"> public:
</span><span class="cx">     StringTypeAdapter&lt;String&gt;(const String&amp; string)
</span><del>-        : m_buffer(string)
</del><ins>+        : m_string(string)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    unsigned length() { return m_buffer.length(); }
</del><ins>+    unsigned length() const { return m_string.length(); }
+    bool is8Bit() const { return m_string.isNull() || m_string.is8Bit(); }
</ins><span class="cx"> 
</span><del>-    bool is8Bit() { return m_buffer.isNull() || m_buffer.is8Bit(); }
-
-    void writeTo(LChar* destination)
</del><ins>+    void writeTo(LChar* destination) const
</ins><span class="cx">     {
</span><del>-        unsigned length = m_buffer.length();
-
-        ASSERT(is8Bit());
-        const LChar* data = m_buffer.characters8();
-        for (unsigned i = 0; i &lt; length; ++i)
-            destination[i] = data[i];
-        
-        WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
</del><ins>+        StringView(m_string).getCharactersWithUpconvert(destination);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void writeTo(UChar* destination)
</del><ins>+    void writeTo(UChar* destination) const
</ins><span class="cx">     {
</span><del>-        unsigned length = m_buffer.length();
-
-        if (is8Bit()) {
-            const LChar* data = m_buffer.characters8();
-            for (unsigned i = 0; i &lt; length; ++i)
-                destination[i] = data[i];
-        } else {
-            const UChar* data = m_buffer.characters16();
-            for (unsigned i = 0; i &lt; length; ++i)
-                destination[i] = data[i];
-        }
-        
-        WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
</del><ins>+        StringView(m_string).getCharactersWithUpconvert(destination);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    const String&amp; m_buffer;
</del><ins>+    const String&amp; m_string;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> template&lt;&gt;
</span><del>-class StringTypeAdapter&lt;AtomicString&gt; {
</del><ins>+class StringTypeAdapter&lt;AtomicString&gt; : public StringTypeAdapter&lt;String&gt; {
</ins><span class="cx"> public:
</span><del>-    StringTypeAdapter&lt;AtomicString&gt;(const AtomicString&amp; string)
-        : m_adapter(string.string())
</del><ins>+    StringTypeAdapter(const AtomicString&amp; string)
+        : StringTypeAdapter&lt;String&gt;(string.string())
</ins><span class="cx">     {
</span><span class="cx">     }
</span><del>-
-    unsigned length() { return m_adapter.length(); }
-
-    bool is8Bit() { return m_adapter.is8Bit(); }
-
-    void writeTo(LChar* destination) { m_adapter.writeTo(destination); }
-    void writeTo(UChar* destination) { m_adapter.writeTo(destination); }
-
-private:
-    StringTypeAdapter&lt;String&gt; m_adapter;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline void sumWithOverflow(unsigned&amp; total, unsigned addend, bool&amp; overflow)
</span></span></pre></div>
<a id="trunkSourceWTFwtftextStringViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/text/StringView.h (174233 => 174234)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/text/StringView.h        2014-10-02 22:25:50 UTC (rev 174233)
+++ trunk/Source/WTF/wtf/text/StringView.h        2014-10-02 22:48:48 UTC (rev 174234)
</span><span class="lines">@@ -26,7 +26,11 @@
</span><span class="cx"> #ifndef StringView_h
</span><span class="cx"> #define StringView_h
</span><span class="cx"> 
</span><del>-#include &lt;wtf/text/StringConcatenate.h&gt;
</del><ins>+#include &lt;unicode/utypes.h&gt;
+#include &lt;wtf/Forward.h&gt;
+#include &lt;wtf/RetainPtr.h&gt;
+#include &lt;wtf/Vector.h&gt;
+#include &lt;wtf/text/LChar.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><span class="lines">@@ -53,28 +57,9 @@
</span><span class="cx">         initialize(characters, length);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    StringView(const StringImpl&amp; string)
-    {
-        if (string.is8Bit())
-            initialize(string.characters8(), string.length());
-        else
-            initialize(string.characters16(), string.length());
-    }
</del><ins>+    StringView(const StringImpl&amp;);
+    StringView(const String&amp;);
</ins><span class="cx"> 
</span><del>-    StringView(const String&amp; string)
-    {
-        if (!string.impl()) {
-            m_characters = nullptr;
-            m_length = 0;
-            return;
-        }
-        if (string.is8Bit()) {
-            initialize(string.characters8(), string.length());
-            return;
-        }
-        initialize(string.characters16(), string.length());
-    }
-
</del><span class="cx">     static StringView empty()
</span><span class="cx">     {
</span><span class="cx">         return StringView(reinterpret_cast&lt;const LChar*&gt;(&quot;&quot;), 0);
</span><span class="lines">@@ -134,36 +119,13 @@
</span><span class="cx">         return StringView(characters16() + start, length);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    String toString() const
-    {
-        if (is8Bit())
-            return String(characters8(), length());
</del><ins>+    String toString() const;
</ins><span class="cx"> 
</span><del>-        return String(characters16(), length());
-    }
</del><ins>+    float toFloat(bool&amp; isValid) const;
+    int toInt(bool&amp; isValid) const;
</ins><span class="cx"> 
</span><del>-    float toFloat(bool&amp; isValid)
-    {
-        if (is8Bit())
-            return charactersToFloat(characters8(), length(), &amp;isValid);
-        return charactersToFloat(characters16(), length(), &amp;isValid);
-    }
</del><ins>+    String toStringWithoutCopying() const;
</ins><span class="cx"> 
</span><del>-    int toInt(bool&amp; isValid)
-    {
-        if (is8Bit())
-            return charactersToInt(characters8(), length(), &amp;isValid);
-        return charactersToInt(characters16(), length(), &amp;isValid);
-    }
-
-    String toStringWithoutCopying() const
-    {
-        if (is8Bit())
-            return StringImpl::createWithoutCopying(characters8(), length());
-
-        return StringImpl::createWithoutCopying(characters16(), length());
-    }
-
</del><span class="cx">     UChar operator[](unsigned index) const
</span><span class="cx">     {
</span><span class="cx">         ASSERT(index &lt; length());
</span><span class="lines">@@ -172,12 +134,7 @@
</span><span class="cx">         return characters16()[index];
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    size_t find(UChar character, unsigned start = 0) const
-    {
-        if (is8Bit())
-            return WTF::find(characters8(), length(), character, start);
-        return WTF::find(characters16(), length(), character, start);
-    }
</del><ins>+    size_t find(UChar character, unsigned start = 0) const;
</ins><span class="cx"> 
</span><span class="cx">     bool contains(UChar c) const { return find(c) != notFound; }
</span><span class="cx"> 
</span><span class="lines">@@ -215,6 +172,34 @@
</span><span class="cx">     unsigned m_length;
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+}
+
+#include &lt;wtf/text/WTFString.h&gt;
+
+namespace WTF {
+
+inline StringView::StringView(const StringImpl&amp; string)
+{
+    if (string.is8Bit())
+        initialize(string.characters8(), string.length());
+    else
+        initialize(string.characters16(), string.length());
+}
+
+inline StringView::StringView(const String&amp; string)
+{
+    if (!string.impl()) {
+        m_characters = nullptr;
+        m_length = 0;
+        return;
+    }
+    if (string.is8Bit()) {
+        initialize(string.characters8(), string.length());
+        return;
+    }
+    initialize(string.characters16(), string.length());
+}
+
</ins><span class="cx"> inline void StringView::getCharactersWithUpconvert(LChar* destination) const
</span><span class="cx"> {
</span><span class="cx">     ASSERT(is8Bit());
</span><span class="lines">@@ -247,6 +232,45 @@
</span><span class="cx">     m_characters = m_upconvertedCharacters.data();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+inline String StringView::toString() const
+{
+    if (is8Bit())
+        return String(characters8(), length());
+
+    return String(characters16(), length());
+}
+
+inline float StringView::toFloat(bool&amp; isValid) const
+{
+    if (is8Bit())
+        return charactersToFloat(characters8(), length(), &amp;isValid);
+    return charactersToFloat(characters16(), length(), &amp;isValid);
+}
+
+inline int StringView::toInt(bool&amp; isValid) const
+{
+    if (is8Bit())
+        return charactersToInt(characters8(), length(), &amp;isValid);
+    return charactersToInt(characters16(), length(), &amp;isValid);
+}
+
+inline String StringView::toStringWithoutCopying() const
+{
+    if (is8Bit())
+        return StringImpl::createWithoutCopying(characters8(), length());
+
+    return StringImpl::createWithoutCopying(characters16(), length());
+}
+
+inline size_t StringView::find(UChar character, unsigned start) const
+{
+    if (is8Bit())
+        return WTF::find(characters8(), length(), character, start);
+    return WTF::find(characters16(), length(), character, start);
+}
+
+template&lt;typename StringType&gt; class StringTypeAdapter;
+
</ins><span class="cx"> template&lt;&gt; class StringTypeAdapter&lt;StringView&gt; {
</span><span class="cx"> public:
</span><span class="cx">     StringTypeAdapter&lt;StringView&gt;(StringView string)
</span></span></pre>
</div>
</div>

</body>
</html>