<!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>[152472] branches/safari-537-branch/Source</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/152472">152472</a></dd>
<dt>Author</dt> <dd>lforschler@apple.com</dd>
<dt>Date</dt> <dd>2013-07-08 16:47:25 -0700 (Mon, 08 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/152052">r152052</a>.  &lt;rdar://problem/14351519&gt;</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari537branchSourceJavaScriptCoreAPIJSStringRefcpp">branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRef.cpp</a></li>
<li><a href="#branchessafari537branchSourceJavaScriptCoreAPIOpaqueJSStringh">branches/safari-537-branch/Source/JavaScriptCore/API/OpaqueJSString.h</a></li>
<li><a href="#branchessafari537branchSourceJavaScriptCoreAPIteststestapic">branches/safari-537-branch/Source/JavaScriptCore/API/tests/testapi.c</a></li>
<li><a href="#branchessafari537branchSourceJavaScriptCoreChangeLog">branches/safari-537-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari537branchSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">branches/safari-537-branch/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#branchessafari537branchSourceWTFChangeLog">branches/safari-537-branch/Source/WTF/ChangeLog</a></li>
<li><a href="#branchessafari537branchSourceWTFwtftextStringImplcpp">branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.cpp</a></li>
<li><a href="#branchessafari537branchSourceWTFwtftextStringImplh">branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari537branchSourceJavaScriptCoreAPIJSStringRefPrivateh">branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRefPrivate.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari537branchSourceJavaScriptCoreAPIJSStringRefcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRef.cpp (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRef.cpp        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRef.cpp        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;JSStringRef.h&quot;
</span><ins>+#include &quot;JSStringRefPrivate.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> #include &quot;InitializeThreading.h&quot;
</span><span class="cx"> #include &quot;OpaqueJSString.h&quot;
</span><span class="lines">@@ -59,6 +60,12 @@
</span><span class="cx">     return OpaqueJSString::create().leakRef();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+JSStringRef JSStringCreateWithCharactersNoCopy(const JSChar* chars, size_t numChars)
+{
+    initializeThreading();
+    return OpaqueJSString::create(StringImpl::createWithoutCopying(chars, numChars, WTF::DoesNotHaveTerminatingNullCharacter)).leakRef();
+}
+
</ins><span class="cx"> JSStringRef JSStringRetain(JSStringRef string)
</span><span class="cx"> {
</span><span class="cx">     string-&gt;ref();
</span></span></pre></div>
<a id="branchessafari537branchSourceJavaScriptCoreAPIJSStringRefPrivatehfromrev152052trunkSourceJavaScriptCoreAPIJSStringRefPrivateh"></a>
<div class="copfile"><h4>Copied: branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRefPrivate.h (from rev 152052, trunk/Source/JavaScriptCore/API/JSStringRefPrivate.h) (0 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRefPrivate.h                                (rev 0)
+++ branches/safari-537-branch/Source/JavaScriptCore/API/JSStringRefPrivate.h        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSStringRefPrivate_h
+#define JSStringRefPrivate_h
+
+#include &lt;JavaScriptCore/JSStringRef.h&gt;
+
+#ifdef __cplusplus
+extern &quot;C&quot; {
+#endif
+
+JS_EXPORT JSStringRef JSStringCreateWithCharactersNoCopy(const JSChar* chars, size_t numChars);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSStringRefPrivate_h */
</ins></span></pre></div>
<a id="branchessafari537branchSourceJavaScriptCoreAPIOpaqueJSStringh"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/JavaScriptCore/API/OpaqueJSString.h (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/JavaScriptCore/API/OpaqueJSString.h        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/JavaScriptCore/API/OpaqueJSString.h        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -70,12 +70,8 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     OpaqueJSString(const String&amp; string)
</span><ins>+        : m_string(string.isolatedCopy())
</ins><span class="cx">     {
</span><del>-        // Make a copy of the source string.
-        if (string.is8Bit())
-            m_string = String(string.characters8(), string.length());
-        else
-            m_string = String(string.characters16(), string.length());
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     OpaqueJSString(const LChar* characters, unsigned length)
</span></span></pre></div>
<a id="branchessafari537branchSourceJavaScriptCoreAPIteststestapic"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/JavaScriptCore/API/tests/testapi.c (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/JavaScriptCore/API/tests/testapi.c        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/JavaScriptCore/API/tests/testapi.c        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include &quot;JSContextRefPrivate.h&quot;
</span><span class="cx"> #include &quot;JSObjectRefPrivate.h&quot;
</span><span class="cx"> #include &quot;JSScriptRefPrivate.h&quot;
</span><ins>+#include &quot;JSStringRefPrivate.h&quot;
</ins><span class="cx"> #include &lt;math.h&gt;
</span><span class="cx"> #define ASSERT_DISABLED 0
</span><span class="cx"> #include &lt;wtf/Assertions.h&gt;
</span><span class="lines">@@ -1205,6 +1206,11 @@
</span><span class="cx">     free(buffer);
</span><span class="cx">     JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);
</span><span class="cx"> 
</span><ins>+    JSChar constantString[] = { 'H', 'e', 'l', 'l', 'o', };
+    JSStringRef constantStringRef = JSStringCreateWithCharactersNoCopy(constantString, sizeof(constantString) / sizeof(constantString[0]));
+    ASSERT(JSStringGetCharactersPtr(constantStringRef) == constantString);
+    JSStringRelease(constantStringRef);
+
</ins><span class="cx">     ASSERT(JSValueGetType(context, NULL) == kJSTypeNull);
</span><span class="cx">     ASSERT(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
</span><span class="cx">     ASSERT(JSValueGetType(context, jsNull) == kJSTypeNull);
</span></span></pre></div>
<a id="branchessafari537branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/JavaScriptCore/ChangeLog (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/JavaScriptCore/ChangeLog        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/JavaScriptCore/ChangeLog        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -1,5 +1,34 @@
</span><span class="cx"> 2013-07-08  Lucas Forschler  &lt;lforschler@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r152052
+
+    2013-06-26  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+            Add JSStringCreateWithCharactersNoCopy SPI
+            https://bugs.webkit.org/show_bug.cgi?id=118074
+            &lt;rdar://problem/14279905&gt;
+
+            Reviewed by Geoffrey Garen.
+
+            * API/JSStringRef.cpp:
+            (JSStringCreateWithCharactersNoCopy):
+            Create a new OpaqueJSString, using the newly added StringImpl::createWithoutCopying function.
+
+            * API/JSStringRefPrivate.h: Added.
+            Add a home for the JSStringCreateWithCharactersNoCopy function.
+
+            * API/OpaqueJSString.h:
+            (OpaqueJSString::OpaqueJSString):
+            Just call isolatedCopy on the passed in string.
+
+            * API/tests/testapi.c:
+            Add an API test for JSStringCreateWithCharactersNoCopy.
+
+            * JavaScriptCore.xcodeproj/project.pbxproj:
+            Add new files.
+
+2013-07-08  Lucas Forschler  &lt;lforschler@apple.com&gt;
+
</ins><span class="cx">         Merge r152314
</span><span class="cx"> 
</span><span class="cx">     2013-07-02  Mark Hahnenberg  &lt;mhahnenberg@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari537branchSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -506,6 +506,7 @@
</span><span class="cx">                 14F7256514EE265E00B1652B /* WeakHandleOwner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F7256314EE265E00B1652B /* WeakHandleOwner.cpp */; };
</span><span class="cx">                 14F7256614EE265E00B1652B /* WeakHandleOwner.h in Headers */ = {isa = PBXBuildFile; fileRef = 14F7256414EE265E00B1652B /* WeakHandleOwner.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 14F97447138C853E00DA1C67 /* HeapRootVisitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 14F97446138C853E00DA1C67 /* HeapRootVisitor.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                1A28D4A8177B71C80007FA3C /* JSStringRefPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A28D4A7177B71C80007FA3C /* JSStringRefPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 1ACF7377171CA6FB00C9BB1E /* Weak.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ACF7376171CA6FB00C9BB1E /* Weak.cpp */; };
</span><span class="cx">                 2600B5A6152BAAA70091EE5F /* JSStringJoiner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2600B5A4152BAAA70091EE5F /* JSStringJoiner.cpp */; };
</span><span class="cx">                 2600B5A7152BAAA70091EE5F /* JSStringJoiner.h in Headers */ = {isa = PBXBuildFile; fileRef = 2600B5A5152BAAA70091EE5F /* JSStringJoiner.h */; };
</span><span class="lines">@@ -1378,6 +1379,7 @@
</span><span class="cx">                 14F7256314EE265E00B1652B /* WeakHandleOwner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakHandleOwner.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 14F7256414EE265E00B1652B /* WeakHandleOwner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakHandleOwner.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 14F97446138C853E00DA1C67 /* HeapRootVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapRootVisitor.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                1A28D4A7177B71C80007FA3C /* JSStringRefPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringRefPrivate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 1ACF7376171CA6FB00C9BB1E /* Weak.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Weak.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1C9051420BA9E8A70081E9D0 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1C9051430BA9E8A70081E9D0 /* JavaScriptCore.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = JavaScriptCore.xcconfig; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -2247,6 +2249,7 @@
</span><span class="cx">                                 E124A8F60E555775003091F1 /* OpaqueJSString.cpp */,
</span><span class="cx">                                 E124A8F50E555775003091F1 /* OpaqueJSString.h */,
</span><span class="cx">                                 5DE3D0F40DD8DDFB00468714 /* WebKitAvailability.h */,
</span><ins>+                                1A28D4A7177B71C80007FA3C /* JSStringRefPrivate.h */,
</ins><span class="cx">                                 C25D709916DE99F400FCA6BC /* JSManagedValue.mm */,
</span><span class="cx">                                 C25D709A16DE99F400FCA6BC /* JSManagedValue.h */,
</span><span class="cx">                                 C2CF39BF16E15A8100DD69BE /* JSAPIWrapperObject.mm */,
</span><span class="lines">@@ -3038,6 +3041,7 @@
</span><span class="cx">                                 144836E7132DA7BE005BE785 /* ConservativeRoots.h in Headers */,
</span><span class="cx">                                 BC18C3F60E16F5CD00B34460 /* ConstructData.h in Headers */,
</span><span class="cx">                                 C2EAD2FC14F0249800A4B159 /* CopiedAllocator.h in Headers */,
</span><ins>+                                1A28D4A8177B71C80007FA3C /* JSStringRefPrivate.h in Headers */,
</ins><span class="cx">                                 C2C8D03014A3CEFC00578E65 /* CopiedBlock.h in Headers */,
</span><span class="cx">                                 C2FC9BD316644DFB00810D33 /* CopiedBlockInlines.h in Headers */,
</span><span class="cx">                                 C2EAA3FA149A835E00FCE112 /* CopiedSpace.h in Headers */,
</span></span></pre></div>
<a id="branchessafari537branchSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/WTF/ChangeLog (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/WTF/ChangeLog        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/WTF/ChangeLog        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -1,5 +1,39 @@
</span><span class="cx"> 2013-07-08  Lucas Forschler  &lt;lforschler@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r152052
+
+    2013-06-26  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+            Add JSStringCreateWithCharactersNoCopy SPI
+            https://bugs.webkit.org/show_bug.cgi?id=118074
+            &lt;rdar://problem/14279905&gt;
+
+            Reviewed by Geoffrey Garen.
+
+            * wtf/text/StringImpl.cpp:
+            (WTF::StringImpl::createFromLiteral):
+            Use the new ConstructWithoutCopying constructor, passing DoesHaveTerminatingNullCharacter to it.
+            Change the other createFromLiteral overload to just call the first.
+
+            (WTF::StringImpl::createWithoutCopying):
+            Add helper functions for creating strings that shouldn't copy their underlying data.
+
+            * wtf/text/StringImpl.h:
+            (WTF::StringImpl::StringImpl):
+            Rename the ConstructFromLiteralTag constructor enum to ConstructWithoutCopyingTag. Change the constructor
+            to take an enum that states whether the string has a terminating null character or not.
+
+            (WTF::StringImpl::createFromLiteral):
+            Call createWithoutCopying.
+
+            (WTF::StringImpl::requiresCopy):
+            Rename this from isASCIILiteral() and make it more generic so it can handle 16-bit strings as well.
+
+            (WTF::StringImpl::isolatedCopy):
+            If this string doesn't have to be copied, just create a new StringImpl object that references the current data.
+
+2013-07-08  Lucas Forschler  &lt;lforschler@apple.com&gt;
+
</ins><span class="cx">         Merge r152306
</span><span class="cx"> 
</span><span class="cx">     2013-07-02  Geoffrey Garen  &lt;ggaren@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari537branchSourceWTFwtftextStringImplcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.cpp (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.cpp        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.cpp        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -158,17 +158,30 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT_WITH_MESSAGE(length, &quot;Use StringImpl::empty() to create an empty string&quot;);
</span><span class="cx">     ASSERT(charactersAreAllASCII&lt;LChar&gt;(reinterpret_cast&lt;const LChar*&gt;(characters), length));
</span><del>-    return adoptRef(new StringImpl(characters, length, ConstructFromLiteral));
</del><ins>+    return adoptRef(new StringImpl(reinterpret_cast&lt;const LChar*&gt;(characters), length, DoesHaveTerminatingNullCharacter, ConstructWithoutCopying));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> PassRefPtr&lt;StringImpl&gt; StringImpl::createFromLiteral(const char* characters)
</span><span class="cx"> {
</span><del>-    size_t length = strlen(characters);
-    ASSERT_WITH_MESSAGE(length, &quot;Use StringImpl::empty() to create an empty string&quot;);
-    ASSERT(charactersAreAllASCII&lt;LChar&gt;(reinterpret_cast&lt;const LChar*&gt;(characters), length));
-    return adoptRef(new StringImpl(characters, length, ConstructFromLiteral));
</del><ins>+    return createFromLiteral(characters, strlen(characters));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+PassRefPtr&lt;StringImpl&gt; StringImpl::createWithoutCopying(const UChar* characters, unsigned length, HasTerminatingNullCharacter hasTerminatingNullCharacter)
+{
+    if (!length)
+        return empty();
+
+    return adoptRef(new StringImpl(characters, length, hasTerminatingNullCharacter, ConstructWithoutCopying));
+}
+
+PassRefPtr&lt;StringImpl&gt; StringImpl::createWithoutCopying(const LChar* characters, unsigned length, HasTerminatingNullCharacter hasTerminatingNullCharacter)
+{
+    if (!length)
+        return empty();
+
+    return adoptRef(new StringImpl(characters, length, hasTerminatingNullCharacter, ConstructWithoutCopying));
+}
+
</ins><span class="cx"> PassRefPtr&lt;StringImpl&gt; StringImpl::createUninitialized(unsigned length, LChar*&amp; data)
</span><span class="cx"> {
</span><span class="cx">     if (!length) {
</span></span></pre></div>
<a id="branchessafari537branchSourceWTFwtftextStringImplh"></a>
<div class="modfile"><h4>Modified: branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.h (152471 => 152472)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.h        2013-07-08 23:41:14 UTC (rev 152471)
+++ branches/safari-537-branch/Source/WTF/wtf/text/StringImpl.h        2013-07-08 23:47:25 UTC (rev 152472)
</span><span class="lines">@@ -68,8 +68,17 @@
</span><span class="cx"> struct UCharBufferTranslator;
</span><span class="cx"> template&lt;typename&gt; class RetainPtr;
</span><span class="cx"> 
</span><del>-enum TextCaseSensitivity { TextCaseSensitive, TextCaseInsensitive };
</del><ins>+enum TextCaseSensitivity {
+    TextCaseSensitive,
+    TextCaseInsensitive
+};
</ins><span class="cx"> 
</span><ins>+enum HasTerminatingNullCharacter {
+    DoesNotHaveTerminatingNullCharacter,
+    DoesHaveTerminatingNullCharacter,
+};
+
+
</ins><span class="cx"> typedef bool (*CharacterMatchFunctionPtr)(UChar);
</span><span class="cx"> typedef bool (*IsWhiteSpaceFunctionPtr)(UChar);
</span><span class="cx"> 
</span><span class="lines">@@ -239,17 +248,31 @@
</span><span class="cx">         STRING_STATS_ADD_8BIT_STRING(m_length);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    enum ConstructFromLiteralTag { ConstructFromLiteral };
-    StringImpl(const char* characters, unsigned length, ConstructFromLiteralTag)
</del><ins>+    enum ConstructWithoutCopyingTag { ConstructWithoutCopying };
+    StringImpl(const UChar* characters, unsigned length, HasTerminatingNullCharacter hasTerminatingNullCharacter, ConstructWithoutCopyingTag)
</ins><span class="cx">         : m_refCount(s_refCountIncrement)
</span><span class="cx">         , m_length(length)
</span><del>-        , m_data8(reinterpret_cast&lt;const LChar*&gt;(characters))
</del><ins>+        , m_data16(characters)
</ins><span class="cx">         , m_buffer(0)
</span><del>-        , m_hashAndFlags(s_hashFlag8BitBuffer | BufferInternal | s_hashFlagHasTerminatingNullCharacter)
</del><ins>+        , m_hashAndFlags(BufferInternal | (hasTerminatingNullCharacter ? s_hashFlagHasTerminatingNullCharacter : 0))
</ins><span class="cx">     {
</span><ins>+        ASSERT(m_data16);
+        ASSERT(m_length);
+        ASSERT(!(m_hashAndFlags &amp; s_hashFlagHasTerminatingNullCharacter) || !characters[length]);
+
+        STRING_STATS_ADD_16BIT_STRING(0);
+    }
+
+    StringImpl(const LChar* characters, unsigned length, HasTerminatingNullCharacter hasTerminatingNullCharacter, ConstructWithoutCopyingTag)
+        : m_refCount(s_refCountIncrement)
+        , m_length(length)
+        , m_data8(characters)
+        , m_buffer(0)
+        , m_hashAndFlags(s_hashFlag8BitBuffer | BufferInternal | (hasTerminatingNullCharacter ? s_hashFlagHasTerminatingNullCharacter : 0))
+    {
</ins><span class="cx">         ASSERT(m_data8);
</span><span class="cx">         ASSERT(m_length);
</span><del>-        ASSERT(!characters[length]);
</del><ins>+        ASSERT(!(m_hashAndFlags &amp; s_hashFlagHasTerminatingNullCharacter) || !characters[length]);
</ins><span class="cx"> 
</span><span class="cx">         STRING_STATS_ADD_8BIT_STRING(0);
</span><span class="cx">     }
</span><span class="lines">@@ -392,17 +415,22 @@
</span><span class="cx">         return adoptRef(new StringImpl(rep-&gt;m_data16 + offset, length, ownerRep));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    WTF_EXPORT_STRING_API static PassRefPtr&lt;StringImpl&gt; createFromLiteral(const char* characters, unsigned length);
</del><span class="cx">     template&lt;unsigned charactersCount&gt;
</span><span class="cx">     ALWAYS_INLINE static PassRefPtr&lt;StringImpl&gt; createFromLiteral(const char (&amp;characters)[charactersCount])
</span><span class="cx">     {
</span><span class="cx">         COMPILE_ASSERT(charactersCount &gt; 1, StringImplFromLiteralNotEmpty);
</span><span class="cx">         COMPILE_ASSERT((charactersCount - 1 &lt;= ((unsigned(~0) - sizeof(StringImpl)) / sizeof(LChar))), StringImplFromLiteralCannotOverflow);
</span><span class="cx"> 
</span><del>-        return createFromLiteral(characters, charactersCount - 1);
</del><ins>+        return createWithoutCopying(reinterpret_cast&lt;const LChar*&gt;(characters), charactersCount - 1, DoesHaveTerminatingNullCharacter);
</ins><span class="cx">     }
</span><ins>+
+    // FIXME: Transition off of these functions to createWithoutCopying instead.
+    WTF_EXPORT_STRING_API static PassRefPtr&lt;StringImpl&gt; createFromLiteral(const char* characters, unsigned length);
</ins><span class="cx">     WTF_EXPORT_STRING_API static PassRefPtr&lt;StringImpl&gt; createFromLiteral(const char* characters);
</span><span class="cx"> 
</span><ins>+    WTF_EXPORT_STRING_API static PassRefPtr&lt;StringImpl&gt; createWithoutCopying(const UChar* characters, unsigned length, HasTerminatingNullCharacter);
+    WTF_EXPORT_STRING_API static PassRefPtr&lt;StringImpl&gt; createWithoutCopying(const LChar* characters, unsigned length, HasTerminatingNullCharacter);
+
</ins><span class="cx">     WTF_EXPORT_STRING_API static PassRefPtr&lt;StringImpl&gt; createUninitialized(unsigned length, LChar*&amp; data);
</span><span class="cx">     WTF_EXPORT_STRING_API static PassRefPtr&lt;StringImpl&gt; createUninitialized(unsigned length, UChar*&amp; data);
</span><span class="cx">     template &lt;typename T&gt; static ALWAYS_INLINE PassRefPtr&lt;StringImpl&gt; tryCreateUninitialized(unsigned length, T*&amp; output)
</span><span class="lines">@@ -736,10 +764,14 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    bool requiresCopy() const
+    {
+        if (bufferOwnership() != BufferInternal)
+            return true;
</ins><span class="cx"> 
</span><del>-    bool isASCIILiteral() const
-    {
-        return is8Bit() &amp;&amp; bufferOwnership() == BufferInternal &amp;&amp; reinterpret_cast&lt;const void*&gt;(m_data8) != reinterpret_cast&lt;const void*&gt;(this + 1);
</del><ins>+        if (is8Bit())
+            return reinterpret_cast&lt;const void*&gt;(m_data8) == reinterpret_cast&lt;const void*&gt;(this + 1);
+        return reinterpret_cast&lt;const void*&gt;(m_data16) == reinterpret_cast&lt;const void*&gt;(this + 1);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
</span><span class="lines">@@ -1328,8 +1360,12 @@
</span><span class="cx"> 
</span><span class="cx"> inline PassRefPtr&lt;StringImpl&gt; StringImpl::isolatedCopy() const
</span><span class="cx"> {
</span><del>-    if (isASCIILiteral())
-        return StringImpl::createFromLiteral(reinterpret_cast&lt;const char*&gt;(m_data8), m_length);
</del><ins>+    if (!requiresCopy()) {
+        if (is8Bit())
+            return StringImpl::createWithoutCopying(m_data8, m_length, hasTerminatingNullCharacter() ? DoesHaveTerminatingNullCharacter : DoesNotHaveTerminatingNullCharacter);
+        return StringImpl::createWithoutCopying(m_data16, m_length, hasTerminatingNullCharacter() ? DoesHaveTerminatingNullCharacter : DoesNotHaveTerminatingNullCharacter);
+    }
+
</ins><span class="cx">     if (is8Bit())
</span><span class="cx">         return create(m_data8, m_length);
</span><span class="cx">     return create(m_data16, m_length);
</span></span></pre>
</div>
</div>

</body>
</html>