<!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>[183001] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/183001">183001</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2015-04-19 21:42:39 -0700 (Sun, 19 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Update RefPtr documentation and deprecation
https://bugs.webkit.org/show_bug.cgi?id=143936

Reviewed by Andreas Kling.

Source/WTF:

* WTF.vcxproj/WTF.vcxproj: Removed PassRef.h
* WTF.vcxproj/WTF.vcxproj.filters: Ditto.
* WTF.xcodeproj/project.pbxproj: Ditto.
* wtf/CMakeLists.txt: Ditto.

Tools:

* Scripts/do-webcore-rename: Put in some DeprecatedPassRefPtr renames.

Websites/webkit.org:

* coding/RefPtr.html: Updated.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFWTFvcxprojWTFvcxproj">trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj</a></li>
<li><a href="#trunkSourceWTFWTFvcxprojWTFvcxprojfilters">trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters</a></li>
<li><a href="#trunkSourceWTFWTFxcodeprojprojectpbxproj">trunk/Source/WTF/WTF.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWTFwtfCMakeListstxt">trunk/Source/WTF/wtf/CMakeLists.txt</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsScriptsdowebcorerename">trunk/Tools/Scripts/do-webcore-rename</a></li>
<li><a href="#trunkWebsiteswebkitorgChangeLog">trunk/Websites/webkit.org/ChangeLog</a></li>
<li><a href="#trunkWebsiteswebkitorgcodingRefPtrhtml">trunk/Websites/webkit.org/coding/RefPtr.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Source/WTF/ChangeLog        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2015-04-19  Darin Adler  &lt;darin@apple.com&gt;
+
+        Update RefPtr documentation and deprecation
+        https://bugs.webkit.org/show_bug.cgi?id=143936
+
+        Reviewed by Andreas Kling.
+
+        * WTF.vcxproj/WTF.vcxproj: Removed PassRef.h
+        * WTF.vcxproj/WTF.vcxproj.filters: Ditto.
+        * WTF.xcodeproj/project.pbxproj: Ditto.
+        * wtf/CMakeLists.txt: Ditto.
+
</ins><span class="cx"> 2015-04-17  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Use ASan poisoning to taint moved-out-of Refs
</span></span></pre></div>
<a id="trunkSourceWTFWTFvcxprojWTFvcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -248,7 +248,6 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\ParallelJobsLibdispatch.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\ParallelJobsOpenMP.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\PassOwnPtr.h&quot; /&gt;
</span><del>-    &lt;ClInclude Include=&quot;..\wtf\PassRef.h&quot; /&gt;
</del><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\PassRefPtr.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\Platform.h&quot; /&gt;
</span><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\PrintStream.h&quot; /&gt;
</span></span></pre></div>
<a id="trunkSourceWTFWTFvcxprojWTFvcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -561,9 +561,6 @@
</span><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\PassOwnPtr.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;wtf&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span><del>-    &lt;ClInclude Include=&quot;..\wtf\PassRef.h&quot;&gt;
-      &lt;Filter&gt;wtf&lt;/Filter&gt;
-    &lt;/ClInclude&gt;
</del><span class="cx">     &lt;ClInclude Include=&quot;..\wtf\PassRefPtr.h&quot;&gt;
</span><span class="cx">       &lt;Filter&gt;wtf&lt;/Filter&gt;
</span><span class="cx">     &lt;/ClInclude&gt;
</span></span></pre></div>
<a id="trunkSourceWTFWTFxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -88,7 +88,6 @@
</span><span class="cx">                 93934BD318A1E8C300D0D6A1 /* StringViewObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */; };
</span><span class="cx">                 93934BD518A1F16900D0D6A1 /* StringViewCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */; };
</span><span class="cx">                 93AC91A818942FC400244939 /* LChar.h in Headers */ = {isa = PBXBuildFile; fileRef = 93AC91A718942FC400244939 /* LChar.h */; };
</span><del>-                93B1AA80180E5AF3004A2F05 /* PassRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B1AA7F180E5AF3004A2F05 /* PassRef.h */; };
</del><span class="cx">                 93F1993E19D7958D00C2390B /* StringView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F1993D19D7958D00C2390B /* StringView.cpp */; };
</span><span class="cx">                 974CFC8E16A4F327006D5404 /* WeakPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 974CFC8D16A4F327006D5404 /* WeakPtr.h */; };
</span><span class="cx">                 9BC70F05176C379D00101DEC /* AtomicStringTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */; };
</span><span class="lines">@@ -377,7 +376,6 @@
</span><span class="cx">                 93934BD218A1E8C300D0D6A1 /* StringViewObjC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = StringViewObjC.mm; path = mac/StringViewObjC.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 93934BD418A1F16900D0D6A1 /* StringViewCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringViewCF.cpp; path = cf/StringViewCF.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 93AC91A718942FC400244939 /* LChar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LChar.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                93B1AA7F180E5AF3004A2F05 /* PassRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PassRef.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><span class="cx">                 93F1993D19D7958D00C2390B /* StringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringView.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 974CFC8D16A4F327006D5404 /* WeakPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeakPtr.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 9BC70F04176C379D00101DEC /* AtomicStringTable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AtomicStringTable.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -807,7 +805,6 @@
</span><span class="cx">                                 A8A472E6151A825B004123FF /* ParallelJobs.h */,
</span><span class="cx">                                 A8A472E9151A825B004123FF /* ParallelJobsLibdispatch.h */,
</span><span class="cx">                                 A8A472EC151A825B004123FF /* PassOwnPtr.h */,
</span><del>-                                93B1AA7F180E5AF3004A2F05 /* PassRef.h */,
</del><span class="cx">                                 A8A472ED151A825B004123FF /* PassRefPtr.h */,
</span><span class="cx">                                 A876DBD7151816E500DADB95 /* Platform.h */,
</span><span class="cx">                                 0F9D335D165DBA73005AD387 /* PrintStream.cpp */,
</span><span class="lines">@@ -1120,7 +1117,6 @@
</span><span class="cx">                                 A8A473E3151A825B004123FF /* Locker.h in Headers */,
</span><span class="cx">                                 A8A473E6151A825B004123FF /* MainThread.h in Headers */,
</span><span class="cx">                                 A8A473E8151A825B004123FF /* MathExtras.h in Headers */,
</span><del>-                                93B1AA80180E5AF3004A2F05 /* PassRef.h in Headers */,
</del><span class="cx">                                 A8A473EA151A825B004123FF /* MD5.h in Headers */,
</span><span class="cx">                                 7CBBA07419BB7FDC00BBF025 /* OSObjectPtr.h in Headers */,
</span><span class="cx">                                 CD5497AD15857D0300B5BC30 /* MediaTime.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWTFwtfCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/CMakeLists.txt (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/CMakeLists.txt        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Source/WTF/wtf/CMakeLists.txt        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -65,7 +65,6 @@
</span><span class="cx">     ParallelJobsLibdispatch.h
</span><span class="cx">     ParallelJobsOpenMP.h
</span><span class="cx">     PassOwnPtr.h
</span><del>-    PassRef.h
</del><span class="cx">     PassRefPtr.h
</span><span class="cx">     Platform.h
</span><span class="cx">     PrintStream.h
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Tools/ChangeLog        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2015-04-19  Darin Adler  &lt;darin@apple.com&gt;
+
+        Update RefPtr documentation and deprecation
+        https://bugs.webkit.org/show_bug.cgi?id=143936
+
+        Reviewed by Andreas Kling.
+
+        * Scripts/do-webcore-rename: Put in some DeprecatedPassRefPtr renames.
+
</ins><span class="cx"> 2015-04-19  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Introduce bytecode intrinsics
</span></span></pre></div>
<a id="trunkToolsScriptsdowebcorerename"></a>
<div class="modfile"><h4>Modified: trunk/Tools/Scripts/do-webcore-rename (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/Scripts/do-webcore-rename        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Tools/Scripts/do-webcore-rename        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -102,6 +102,10 @@
</span><span class="cx"> );
</span><span class="cx"> 
</span><span class="cx"> my %renamesContemplatedForTheFuture = (
</span><ins>+    &quot;PassRefPtr&quot; =&gt; &quot;DeprecatedPassRefPtr&quot;,
+    &quot;OwnPtr&quot; =&gt; &quot;DeprecatedOwnPtr&quot;,
+    &quot;PassOwnPtr&quot; =&gt; &quot;DeprecatedPassOwnPtr&quot;,
+
</ins><span class="cx">     &quot;HTMLPlugInImageElement&quot; =&gt; &quot;HTMLEmbeddedObjectElement&quot;,
</span><span class="cx">     &quot;isPlugInImageElement&quot; =&gt; &quot;isEmbeddedObjectElement&quot;,
</span><span class="cx">     &quot;isHTMLPlugInImageElement&quot; =&gt; &quot;isHTMLEmbeddedObjectElement&quot;,
</span></span></pre></div>
<a id="trunkWebsiteswebkitorgChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Websites/webkit.org/ChangeLog (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/webkit.org/ChangeLog        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Websites/webkit.org/ChangeLog        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2015-04-19  Darin Adler  &lt;darin@apple.com&gt;
+
+        Update RefPtr documentation and deprecation
+        https://bugs.webkit.org/show_bug.cgi?id=143936
+
+        Reviewed by Andreas Kling.
+
+        * coding/RefPtr.html: Updated.
+
</ins><span class="cx"> 2015-03-10  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix warning about loading insecure content from secure webkit.org/blog
</span></span></pre></div>
<a id="trunkWebsiteswebkitorgcodingRefPtrhtml"></a>
<div class="modfile"><h4>Modified: trunk/Websites/webkit.org/coding/RefPtr.html (183000 => 183001)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Websites/webkit.org/coding/RefPtr.html        2015-04-20 04:17:27 UTC (rev 183000)
+++ trunk/Websites/webkit.org/coding/RefPtr.html        2015-04-20 04:42:39 UTC (rev 183001)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><del>-&lt;?php 
-    $title=&quot;RefPtr and PassRefPtr Basics&quot;;
</del><ins>+&lt;?php
+    $title=&quot;RefPtr Basics&quot;;
</ins><span class="cx">     include(&quot;../header.inc&quot;); 
</span><span class="cx"> ?&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -16,40 +16,43 @@
</span><span class="cx">     }
</span><span class="cx"> &lt;/style&gt;
</span><span class="cx"> 
</span><del>-&lt;h1&gt;&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; and &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; Basics&lt;/h1&gt;
</del><ins>+&lt;h1&gt;&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; Basics&lt;/h1&gt;
</ins><span class="cx"> &lt;div&gt;Darin Adler&lt;/div&gt;
</span><del>-&lt;div&gt;Version 4, 2010-08-27&lt;/div&gt;
</del><ins>+&lt;div&gt;Version 5, 2015-04-19&lt;/div&gt;
</ins><span class="cx"> 
</span><span class="cx"> &lt;h2&gt;History&lt;/h2&gt;
</span><span class="cx"> 
</span><del>-&lt;p&gt;Many objects in WebKit are reference counted. The pattern used is that classes have
-member functions &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt; and &lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt;
-that increment and decrement the reference count. Each call to &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt;
-has to be matched by a call to &lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt;. When the function is called
</del><ins>+&lt;p&gt;Many objects in WebKit are reference counted. The pattern is that classes have
+member functions named &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt; and &lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt;
+that increment and decrement a reference count. When the &lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt; function is called
</ins><span class="cx"> on an object with a reference count of 1, the object is deleted. Many classes in WebKit implement
</span><span class="cx"> this pattern by deriving from the &lt;span class=&quot;class&quot;&gt;RefCounted&lt;/span&gt; class template.&lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;p&gt;Back in 2005, we discovered that there were many memory leaks, especially in HTML
</span><span class="cx"> editing code, caused by misuse of &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt; and
</span><del>-&lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt; calls.&lt;/p&gt;
-
-&lt;p&gt;We wanted
-to use smart pointers to mitigate the problem. However, some early experiments showed that
</del><ins>+&lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt; calls.
+We decided to use smart pointers to mitigate the problem. Early experiments showed that
</ins><span class="cx"> smart pointers led to additional manipulation of reference counts that hurt performance.
</span><del>-For example, for a function that took a smart pointer as a parameter and returned that same smart
-pointer as a return value, just passing the parameter and returning the value would increment
</del><ins>+For example, for a function that took a smart pointer as an argument and returned that same smart
+pointer as a return value, passing the parameter and returning the value would increment
</ins><span class="cx"> and then decrement the reference count two to four times
</span><del>-as the object moved from one smart pointer to another. So we looked for an
-idiom that would let us use smart pointers and avoid this reference count churn.&lt;/p&gt;
</del><ins>+as the object moved from one smart pointer to another.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;The inspiration for a solution came from the C++ standard class template &lt;span class=&quot;class&quot;&gt;auto_ptr&lt;/span&gt;.
-These objects implement a model where assignment is transfer of ownership. When you assign
-from one &lt;span class=&quot;class&quot;&gt;auto_ptr&lt;/span&gt; to another, the donor becomes 0.&lt;/p&gt;
</del><ins>+&lt;p&gt;We solved that problem in 2005 with a set of smart pointer class templates. C++ move semantics,
+introduced in C++11, made it possible to streamline those class templates without
+reintroducing reference count churn.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;Maciej Stachowiak devised a pair of class templates, &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
-and &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;, that implement this scheme
-for WebCore’s intrusive reference counting.&lt;/p&gt;
</del><ins>+&lt;p&gt;Later, in 2013, we noticed that our use of pointers in general, and smart pointers in particular,
+was causing a proliferation of null checks and uncertainty about what can be null.
+We started using references rather than pointers wherever possible in WebKit code.&lt;/p&gt;
</ins><span class="cx"> 
</span><ins>+&lt;p&gt;Maciej Stachowiak created the class template, &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;,
+that implements WebKit’s intrusive reference counting, and we have since adapted it so that it
+works well with move semantics. Andreas Kling created a related class template,
+&lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt;, which works with RefPtr and provides clarity and
+even greater efficiency when dealing with
+reference counted objects in contexts where there is no need for a null pointer.&lt;/p&gt;
+
</ins><span class="cx"> &lt;h2&gt;Raw pointers&lt;/h2&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;p&gt;When discussing smart pointers such as the &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
</span><span class="lines">@@ -60,14 +63,9 @@
</span><span class="cx"> 
</span><span class="cx"> class Document {
</span><span class="cx">     &lt;span class=&quot;comment&quot;&gt;...&lt;/span&gt;
</span><del>-    Title* m_title;
</del><ins>+    Title* m_title { nullptr };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-Document::Document()
-    : m_title(0)
-{
-}
-
</del><span class="cx"> Document::~Document()
</span><span class="cx"> {
</span><span class="cx">     if (m_title)
</span><span class="lines">@@ -85,7 +83,7 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;h2&gt;&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;&lt;/h2&gt;
</span><span class="cx"> 
</span><del>-&lt;p&gt;&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; is a simple smart pointer class that calls &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt;
</del><ins>+&lt;p&gt;&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; is a smart pointer class template that calls &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt;
</ins><span class="cx"> on incoming values and
</span><span class="cx"> &lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt; on outgoing values.
</span><span class="cx"> &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; works on any object with both a &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt; and
</span><span class="lines">@@ -93,7 +91,7 @@
</span><span class="cx"> Here’s the setter function example, written with &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;:&lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// example, not preferred style&lt;/span&gt;
</span><del>- 
</del><ins>+
</ins><span class="cx"> class Document {
</span><span class="cx">     &lt;span class=&quot;comment&quot;&gt;...&lt;/span&gt;
</span><span class="cx">     RefPtr&amp;lt;Title&amp;gt; m_title;
</span><span class="lines">@@ -104,208 +102,166 @@
</span><span class="cx">     m_title = title;
</span><span class="cx"> }&lt;/pre&gt;
</span><span class="cx"> 
</span><del>-&lt;p&gt;Use of &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; alone can lead to reference count churn.&lt;/p&gt;
</del><ins>+&lt;p&gt;Functions that take take ownership of reference counted arguments can lead to reference count churn.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// example, not preferred style; should use RefCounted and adoptRef (see below)&lt;/span&gt;
</del><ins>+&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// example, not preferred style
</ins><span class="cx">  
</span><del>-RefPtr&amp;lt;Node&amp;gt; createSpecialNode()
-{
-    RefPtr&amp;lt;Node&amp;gt; a = new Node;
-    a-&amp;gt;setSpecial(true);
-    return a;
-}
</del><ins>+RefPtr&amp;lt;Title&amp;gt; untitledTitle = titleFactory().createUniqueUntitledTitle();
</ins><span class="cx"> 
</span><del>-RefPtr&amp;lt;Node&amp;gt; b = createSpecialNode();&lt;/pre&gt;
</del><ins>+document.setTitle(untitledTitle);&lt;/pre&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;For purposes of this discussion, lets assume that the node object starts with a
-reference count of 0 (more on this later). When it’s assigned to &lt;span class=&quot;variable&quot;&gt;a&lt;/span&gt;,
-the reference count is incremented to 1. The reference count is incremented to 2 to
-create the return value, then decremented back to 1 when &lt;span class=&quot;variable&quot;&gt;a&lt;/span&gt; is destroyed.
-Then the reference count is incremented to 2 to create &lt;span class=&quot;variable&quot;&gt;b&lt;/span&gt;, and then decremented back
-to 1 when the return value of &lt;span class=&quot;function&quot;&gt;createSpecialNode&lt;/span&gt; is destroyed.&lt;/p&gt;
</del><ins>+&lt;p&gt;The title starts with a reference count of 1. The &lt;span class=&quot;function&quot;&gt;setTitle&lt;/span&gt; function stores it in the data member,
+and the reference count is incremented to 2. Then the local variable &lt;span class=&quot;variable&quot;&gt;untitledTitle&lt;/span&gt; goes out of
+scope and the reference count is decremented back to 1.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;(If the compiler implements the
-&lt;a href=&quot;http://en.wikipedia.org/wiki/Return_value_optimization&quot;&gt;return value optimization&lt;/a&gt;,
-there may be one less increment and decrement of the reference count.)&lt;/p&gt;
</del><ins>+&lt;p&gt;The way to define a function that takes ownership of an object is to use an rvalue reference.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;The overhead of reference count churn is even greater when both function arguments and return
-values are involved. The solution is &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;.&lt;/p&gt;
</del><ins>+&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// preferred style&lt;/span&gt;

+class Document {
+    &lt;span class=&quot;comment&quot;&gt;...&lt;/span&gt;
+    RefPtr&amp;lt;Title&amp;gt; m_title;
+}
</ins><span class="cx"> 
</span><del>-&lt;h2&gt;&lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;&lt;/h2&gt;
-
-&lt;p&gt;&lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; is like &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; with a difference.
-When you copy a &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; or
-assign the value of a &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; to a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; or
-another &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;, the original
-pointer value is set to 0; the operation is done without any change to the reference count.
-Let’s take a look at a new version of our example:&lt;/p&gt;
-
-&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// example, not preferred style; should use RefCounted and adoptRef (see below)&lt;/span&gt;
-
-PassRefPtr&amp;lt;Node&amp;gt; createSpecialNode()
</del><ins>+void Document::setTitle(RefPtr&amp;lt;Title&amp;gt;&amp;amp;&amp;amp; title)
</ins><span class="cx"> {
</span><del>-    PassRefPtr&amp;lt;Node&amp;gt; a = new Node;
-    a-&amp;gt;setSpecial(true);
-    return a;
</del><ins>+    m_title = WTF::move(title);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&amp;lt;Node&amp;gt; b = createSpecialNode();&lt;/pre&gt;
</del><ins>+&lt;span class=&quot;comment&quot;&gt;...&lt;/span&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;The node object starts with a reference count of 0. When it’s assigned to &lt;span class=&quot;variable&quot;&gt;a&lt;/span&gt;,
-the reference count is incremented to 1. Then &lt;span class=&quot;variable&quot;&gt;a&lt;/span&gt; gets set to 0 when the return
-value &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; is created. Then the return value is set to 0 when
-&lt;span class=&quot;variable&quot;&gt;b&lt;/span&gt; is created.&lt;/p&gt;
</del><ins>+RefPtr&amp;lt;Title&amp;gt; untitledTitle = titleFactory().createUniqueUntitledTitle();
</ins><span class="cx"> 
</span><del>-&lt;p&gt;However, as the Safari team learned when we started programming with &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;,
-the rule that a pointer becomes 0 when it’s assigned to another variable can easily lead to mistakes.&lt;/p&gt;
</del><ins>+document.setTitle(WTF::move(untitledTitle));&lt;/pre&gt;
</ins><span class="cx"> 
</span><del>-&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// warning, will dereference a null pointer and will not work&lt;/span&gt;

-static RefPtr&amp;lt;Ring&amp;gt; g_oneRingToRuleThemAll;
</del><ins>+&lt;p&gt;The title makes it all the way into the data member with a reference count of 1;
+it’s never incremented or decremented.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-void finish(PassRefPtr&amp;lt;Ring&amp;gt; ring)
-{
-    g_oneRingToRuleThemAll = ring;
-    &lt;span class=&quot;comment&quot;&gt;...&lt;/span&gt;
-    ring-&amp;gt;wear();
-}&lt;/pre&gt;
</del><ins>+&lt;p&gt;Note the use of &lt;span class=&quot;function&quot;&gt;WTF::move&lt;/span&gt;
+instead of &lt;span class=&quot;function&quot;&gt;std::move&lt;/span&gt;.
+The WTF version adds a couple of compile time checks to catch common errors, and should be
+used throughout the WebKit project in place of &lt;span class=&quot;function&quot;&gt;std::move&lt;/span&gt;.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;By the time &lt;span class=&quot;function&quot;&gt;wear&lt;/span&gt; is called, &lt;span class=&quot;variable&quot;&gt;ring&lt;/span&gt;
-is already 0. To avoid this, we recommend &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; only for
-function argument and result types, copying arguments into &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
-local variables.&lt;/p&gt;
</del><ins>+&lt;h2&gt;&lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt;&lt;/h2&gt;
</ins><span class="cx"> 
</span><del>-&lt;pre class=&quot;code&quot;&gt;static RefPtr&amp;lt;Ring&amp;gt; g_oneRingToRuleThemAll;
</del><ins>+&lt;p&gt;&lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; is like &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;, except that it
+acts like a reference rather than a pointer; it doesn’t have a null value.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-void finish(PassRefPtr&amp;lt;Ring&amp;gt; prpRing)
-{
-    RefPtr&amp;lt;Ring&amp;gt; ring = prpRing;
-    g_oneRingToRuleThemAll = ring;
-    &lt;span class=&quot;comment&quot;&gt;...&lt;/span&gt;
-    ring-&amp;gt;wear();
-}&lt;/pre&gt;
</del><ins>+&lt;p&gt;&lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; works particularly well with return values; it’s often
+straightforward to be sure that a newly created object will never be null.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;h2&gt;Mixing &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; and &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;&lt;/h2&gt;
-
-&lt;p&gt;Since we recommend use of &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; in all cases except when passing arguments to or
-returning values from a function, there will be times when you have a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
-and wish to transfer ownership as &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; does.
-&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; has a member function named
-&lt;span class=&quot;function&quot;&gt;release&lt;/span&gt; that does the trick. It sets the value of the original
-&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; to 0 and constructs a &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;, without
-changing reference counts.&lt;/p&gt;
-
-&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// example, not preferred style; should use RefCounted and adoptRef (see below)&lt;/span&gt;
</del><ins>+&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// preferred style&lt;/span&gt;
</ins><span class="cx">  
</span><del>-PassRefPtr&amp;lt;Node&amp;gt; createSpecialNode()
</del><ins>+Ref&amp;lt;Title&amp;gt; TitleFactory::createUniqueUntitledTitle()
</ins><span class="cx"> {
</span><del>-    RefPtr&amp;lt;Node&amp;gt; a = new Node;
-    a-&amp;gt;setCreated(true);
-    return a.release();
-}
</del><ins>+    return createTitle(&quot;untitled &quot; + m_nextAvailableUntitledNumber++);
+}&lt;/pre&gt;
</ins><span class="cx"> 
</span><del>-RefPtr&amp;lt;Node&amp;gt; b = createSpecialNode();&lt;/pre&gt;
</del><ins>+&lt;p&gt;Using &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; helps makes it clear to the caller that this function will never return null.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;This keeps the efficiency of &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; while reducing the chance
-that its relatively tricky semantics will cause problems.&lt;/p&gt;
-
</del><span class="cx"> &lt;h2&gt;Mixing with raw pointers&lt;/h2&gt;
</span><span class="cx"> 
</span><ins>+&lt;p&gt;The &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; class mixes with raw pointers much as the smart
+pointers in the C++ standard library, such as &lt;span class=&quot;class&quot;&gt;std::unique_ptr&lt;/span&gt;, do.&lt;/p&gt;
+
</ins><span class="cx"> &lt;p&gt;When using a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; to call a function that takes a raw pointer,
</span><span class="cx"> use the &lt;span class=&quot;function&quot;&gt;get&lt;/span&gt; function.&lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;pre class=&quot;code&quot;&gt;printNode(stderr, a.get());&lt;/pre&gt;
</span><span class="cx"> 
</span><del>-&lt;p&gt;However, many operations can be done on a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
-or &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; directly, without resorting to an explicit &lt;span class=&quot;function&quot;&gt;get&lt;/span&gt; call.&lt;/p&gt;
</del><ins>+&lt;p&gt;With a &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt;, the &lt;span class=&quot;function&quot;&gt;get&lt;/span&gt; function
+produces a raw reference, and the &lt;span class=&quot;function&quot;&gt;ptr&lt;/span&gt; function produces a raw pointer.&lt;/p&gt;
</ins><span class="cx"> 
</span><del>-&lt;pre class=&quot;code&quot;&gt;RefPtr&amp;lt;Node&amp;gt; a = createSpecialNode();
-Node* b = getOrdinaryNode();
</del><ins>+&lt;pre class=&quot;code&quot;&gt;printString(stderr, a.get().caption());
+printNode(stderr, a.ptr());&lt;/pre&gt;
</ins><span class="cx"> 
</span><ins>+&lt;p&gt;Many operations can be done on a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
+directly, without resorting to an explicit &lt;span class=&quot;function&quot;&gt;get&lt;/span&gt; call.&lt;/p&gt;
+
+&lt;pre class=&quot;code&quot;&gt;Ref&amp;lt;Node&amp;gt; a = createSpecialNode();
+RefPtr&amp;lt;Node&amp;gt; b = findNode();
+Node* c = getOrdinaryNode();
+
</ins><span class="cx"> &lt;span class=&quot;comment&quot;&gt;// the * operator&lt;/span&gt;
</span><del>-*a = value;
</del><ins>+*b = value;
</ins><span class="cx"> 
</span><span class="cx"> &lt;span class=&quot;comment&quot;&gt;// the -&amp;gt; operator&lt;/span&gt;
</span><span class="cx"> a-&amp;gt;clear();
</span><ins>+b-&amp;gt;clear();
</ins><span class="cx"> 
</span><span class="cx"> &lt;span class=&quot;comment&quot;&gt;// null check in an if statement&lt;/span&gt;
</span><del>-if (a)
</del><ins>+if (b)
</ins><span class="cx">     log(&quot;not empty&quot;);
</span><span class="cx"> 
</span><span class="cx"> &lt;span class=&quot;comment&quot;&gt;// the ! operator&lt;/span&gt;
</span><del>-if (!a)
</del><ins>+if (!b)
</ins><span class="cx">     log(&quot;empty&quot;);
</span><span class="cx"> 
</span><span class="cx"> &lt;span class=&quot;comment&quot;&gt;// the == and != operators, mixing with raw pointers&lt;/span&gt;
</span><del>-if (a == b)
</del><ins>+if (b == c)
</ins><span class="cx">     log(&quot;equal&quot;);
</span><del>-if (a != b)
</del><ins>+if (b != c)
</ins><span class="cx">     log(&quot;not equal&quot;);
</span><span class="cx"> 
</span><span class="cx"> &lt;span class=&quot;comment&quot;&gt;// some type casts&lt;/span&gt;
</span><del>-RefPtr&amp;lt;DerivedNode&amp;gt; d = static_pointer_cast&amp;lt;DerivedNode&amp;gt;(a);&lt;/pre&gt;
</del><ins>+RefPtr&amp;lt;DerivedNode&amp;gt; d = static_pointer_cast&amp;lt;DerivedNode&amp;gt;(d);&lt;/pre&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;Normally, &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; and &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;
-enforce a simple rule; they always balance &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt; and
</del><ins>+&lt;p&gt;Normally, &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; enforces a simple rule; it always
+balances &lt;span class=&quot;function&quot;&gt;ref&lt;/span&gt; and
</ins><span class="cx"> &lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt; calls, guaranteeing a programmer can’t miss a
</span><del>-&lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt;. But in the case where we have a raw pointer,
</del><ins>+&lt;span class=&quot;function&quot;&gt;deref&lt;/span&gt;. But in the case where we start with a raw pointer,
</ins><span class="cx"> already have a reference count, and want to transfer ownership the
</span><span class="cx"> &lt;span class=&quot;function&quot;&gt;adoptRef&lt;/span&gt; function should be used.&lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// warning, requires a pointer that already has a ref&lt;/span&gt;
</span><span class="cx"> RefPtr&amp;lt;Node&amp;gt; node = adoptRef(rawNodePointer);&lt;/pre&gt;
</span><span class="cx"> 
</span><del>-&lt;p&gt;To transfer from a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; to a raw pointer without
-changing the reference count, &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; provides the
</del><ins>+&lt;p&gt;In the rare case where we have a need to transfer from a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
+to a raw pointer without changing the reference count, use the
</ins><span class="cx"> &lt;span class=&quot;function&quot;&gt;leakRef&lt;/span&gt; function.&lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// warning, results in a pointer that must get an explicit deref&lt;/span&gt;
</span><span class="cx"> RefPtr&amp;lt;Node&amp;gt; node = createSpecialNode();
</span><del>-Node* rawNodePointer = node.release().leakRef();&lt;/pre&gt;
</del><ins>+Node* rawNodePointer = node.leakRef();&lt;/pre&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;Since &lt;span class=&quot;function&quot;&gt;leakRef&lt;/span&gt; is rarely used, it’s provided only in the
-&lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; class, hence the need to call &lt;span class=&quot;function&quot;&gt;release&lt;/span&gt;,
-then &lt;span class=&quot;function&quot;&gt;leakRef&lt;/span&gt;.&lt;/p&gt;
-
</del><span class="cx"> &lt;h2&gt;RefPtr and new objects&lt;/h2&gt;
</span><span class="cx"> 
</span><del>-&lt;p&gt;In the examples in this discussion, we talked about objects with a reference
-count of 0. However, for efficiency and simplicity, the &lt;span class=&quot;class&quot;&gt;RefCounted&lt;/span&gt; class doesn't
-use a reference count of 0 at all. Objects are created with a reference count
</del><ins>+&lt;p&gt;New objects of classes that make use of the &lt;span class=&quot;class&quot;&gt;RefCounted&lt;/span&gt; class template
+are created with a reference count
</ins><span class="cx"> of 1. The best programming idiom to use is to put such objects right into a
</span><del>-&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; to make it impossible to forget to deref the object when done with
</del><ins>+&lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; to make it impossible to forget to deref the object when done with
</ins><span class="cx"> it. This means that anyone calling new on such an object should immediately
</span><del>-call adoptRef. In WebCore we use functions named create instead of direct calls
-to new.&lt;/p&gt;
</del><ins>+call adoptRef. In WebKit we use functions named create instead of direct calls
+to new for these classes.&lt;/p&gt;
</ins><span class="cx"> 
</span><span class="cx"> &lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// preferred style&lt;/span&gt;
</span><span class="cx">  
</span><del>-PassRefPtr&amp;lt;Node&amp;gt; Node::create()
</del><ins>+Ref&amp;lt;Node&amp;gt; Node::create()
</ins><span class="cx"> {
</span><del>-    return adoptRef(new Node);
</del><ins>+    return adoptRef(*new Node);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&amp;lt;Node&amp;gt; e = Node::create();&lt;/pre&gt;
</del><ins>+Ref&amp;lt;Node&amp;gt; e = Node::create();&lt;/pre&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;Because of the way &lt;span class=&quot;function&quot;&gt;adoptRef&lt;/span&gt; and
-&lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; are implemented, this is an efficient idiom.
-The object starts with a reference count of 1 and no manipulation of the reference
-count happens at all.&lt;/p&gt;
</del><ins>+&lt;p&gt;Because of the way &lt;span class=&quot;function&quot;&gt;adoptRef&lt;/span&gt; is implemented,
+this is an efficient idiom.
+The object starts with a reference count of 1 and no code is generated to
+examine or modify the reference count.&lt;/p&gt;
</ins><span class="cx"> 
</span><span class="cx"> &lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// preferred style&lt;/span&gt;
</span><span class="cx">  
</span><del>-PassRefPtr&amp;lt;Node&amp;gt; createSpecialNode()
</del><ins>+Ref&amp;lt;Node&amp;gt; createSpecialNode()
</ins><span class="cx"> {
</span><del>-    RefPtr&amp;lt;Node&amp;gt; a = Node::create();
</del><ins>+    Ref&amp;lt;Node&amp;gt; a = Node::create();
</ins><span class="cx">     a-&amp;gt;setCreated(true);
</span><del>-    return a.release();
</del><ins>+    return a;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&amp;lt;Node&amp;gt; b = createSpecialNode();&lt;/pre&gt;
</del><ins>+Ref&amp;lt;Node&amp;gt; b = createSpecialNode();&lt;/pre&gt;
</ins><span class="cx"> 
</span><del>-&lt;p&gt;The node object is put into a &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; by a call
</del><ins>+&lt;p&gt;The node object is put into a &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; by a call
</ins><span class="cx"> to &lt;span class=&quot;function&quot;&gt;adoptRef&lt;/span&gt; inside &lt;span class=&quot;function&quot;&gt;Node::create&lt;/span&gt;,
</span><del>-then passes into &lt;span class=&quot;variable&quot;&gt;a&lt;/span&gt; and is released and passes into
</del><ins>+then passes into &lt;span class=&quot;variable&quot;&gt;a&lt;/span&gt; and is passed into
</ins><span class="cx"> &lt;span class=&quot;variable&quot;&gt;b&lt;/span&gt;, all without touching the reference count.&lt;/p&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;p&gt;The &lt;span class=&quot;class&quot;&gt;RefCounted&lt;/span&gt; class implements a runtime check
</span><span class="lines">@@ -315,56 +271,69 @@
</span><span class="cx"> &lt;h2&gt;Guidelines&lt;/h2&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;p&gt;We’ve developed these guidelines for use of &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;
</span><del>-and &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt; in WebKit code.&lt;/p&gt;
</del><ins>+and &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; in WebKit code.&lt;/p&gt;
</ins><span class="cx"> 
</span><span class="cx"> &lt;h3&gt;Local variables&lt;/h3&gt;
</span><span class="cx"> &lt;ul&gt;
</span><del>-&lt;li&gt;If ownership and lifetime are guaranteed, a local variable can be a raw pointer.&lt;/li&gt;
</del><ins>+&lt;li&gt;If ownership and lifetime are guaranteed, a local variable can be a raw reference or pointer.&lt;/li&gt;
</ins><span class="cx"> &lt;li&gt;If the code needs to hold ownership or guarantee lifetime, a local variable should
</span><del>-be a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;.&lt;/li&gt;
-&lt;li&gt;Local variables should never be &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;.&lt;/li&gt;
</del><ins>+be a &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt;, or if it can be null, a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;.&lt;/li&gt;
</ins><span class="cx"> &lt;/ul&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;h3&gt;Data members&lt;/h3&gt;
</span><span class="cx"> &lt;ul&gt;
</span><del>-&lt;li&gt;If ownership and lifetime are guaranteed, a data member can be a raw pointer.&lt;/li&gt;
</del><ins>+&lt;li&gt;If ownership and lifetime are guaranteed, a data member can be a raw reference or pointer.&lt;/li&gt;
</ins><span class="cx"> &lt;li&gt;If the class needs to hold ownership or guarantee lifetime, the data member should
</span><del>-be a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;.&lt;/li&gt;
-&lt;li&gt;Data members should never be &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;.&lt;/li&gt;
</del><ins>+be a &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; or &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;.&lt;/li&gt;
</ins><span class="cx"> &lt;/ul&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;h3&gt;Function arguments&lt;/h3&gt;
</span><span class="cx"> &lt;ul&gt;
</span><del>-&lt;li&gt;If a function does not take ownership of an object, the argument should be a raw pointer.&lt;/li&gt;
-&lt;li&gt;If a function does take ownership of an object, the argument should be a &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;.
-This includes most setter functions.
-Unless the use of the argument is very simple, the argument should be transferred to a
-&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; at the start of the function; the argument can be named with
-a “prp” prefix in such cases.&lt;/li&gt;
</del><ins>+&lt;li&gt;If a function does not take ownership of an object, the argument should be a raw reference or raw pointer.&lt;/li&gt;
+&lt;li&gt;If a function does take ownership of an object, the argument should be a &lt;span class=&quot;class&quot;&gt;Ref&amp;amp;&amp;amp;&lt;/span&gt;
+or a &lt;span class=&quot;class&quot;&gt;RefPtr&amp;amp;&amp;amp;&lt;/span&gt;. This includes many setter functions.
</ins><span class="cx"> &lt;/ul&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;h3&gt;Function results&lt;/h3&gt;
</span><span class="cx"> &lt;ul&gt;
</span><span class="cx"> &lt;li&gt;If a function’s result is an object, but ownership is not being transferred, the result
</span><del>-should be a raw pointer. This includes most getter functions.&lt;/li&gt;
</del><ins>+should be a raw reference or raw pointer. This includes most getter functions.&lt;/li&gt;
</ins><span class="cx"> &lt;li&gt;If a function’s result is a new object or ownership is being transferred for any other
</span><del>-reason, the result should be a &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;.
-Since local variables are typically &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;, it’s common to call
-&lt;span class=&quot;function&quot;&gt;release&lt;/span&gt; in the return statement to transfer the
-&lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; to the &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;.&lt;/li&gt;
</del><ins>+reason, the result should be a &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; or &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt;.&lt;/li&gt;
</ins><span class="cx"> &lt;/ul&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;h3&gt;New objects&lt;/h3&gt;
</span><span class="cx"> &lt;ul&gt;
</span><del>-&lt;li&gt;New objects should be put into a &lt;span class=&quot;class&quot;&gt;RefPtr&lt;/span&gt; as soon as possible
</del><ins>+&lt;li&gt;New objects should be put into a &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; as soon as possible
</ins><span class="cx"> after creation to allow the smart pointers to do all reference counting automatically.&lt;/li&gt;
</span><span class="cx"> &lt;li&gt;For &lt;span class=&quot;class&quot;&gt;RefCounted&lt;/span&gt; objects, the above should be done with the
</span><span class="cx"> &lt;span class=&quot;function&quot;&gt;adoptRef&lt;/span&gt; function.&lt;/li&gt;
</span><span class="cx"> &lt;li&gt;Best idiom is to use a private constructor and a public
</span><span class="cx"> &lt;span class=&quot;function&quot;&gt;create&lt;/span&gt; function that
</span><del>-returns a &lt;span class=&quot;class&quot;&gt;PassRefPtr&lt;/span&gt;.&lt;/li&gt;
</del><ins>+returns a &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt;.&lt;/li&gt;
</ins><span class="cx"> &lt;/ul&gt;
</span><span class="cx"> 
</span><ins>+&lt;h2&gt;Pitfalls&lt;/h2&gt;
+
+&lt;h3&gt;PassRefPtr&lt;/h3&gt;
+&lt;p&gt;Programmers who worked on WebKit before C++11 are familiar with a class template called PassRefPtr
+(soon to be renamed to DeprecatedPassRefPtr) and you will see it in older WebKit code.&lt;/p&gt;
+&lt;ul&gt;
+&lt;li&gt;Any function result or local variable of type PassRefPtr should be replaced with one of type RefPtr or Ref.&lt;/li&gt;
+&lt;li&gt;Any argument of type PassRefPtr should be replaced with one of type RefPtr&amp;amp;&amp;amp; or Ref&amp;amp;&amp;amp;.&lt;/li&gt;
+&lt;li&gt;Code calling RefPtr::release to turn a RefPtr into a PassRefPtr should instead call WTF::move.&lt;/li&gt;
+&lt;/ul&gt;
+
+&lt;h3&gt;Common mistakes&lt;/h3&gt;
+&lt;ul&gt;
+&lt;li&gt;Giving a function argument a type of Ref, RefPtr, Ref&amp;amp;&amp;amp;, or RefPtr&amp;amp;&amp;amp;
+when it should instead be a raw reference or raw pointer. A function that sometimes takes ownership
+can work just fine with a raw reference or raw pointer. The rvalue reference form is appropriate
+when passing ownership is the primary way the function is used and the is case that needs to be optimized.
+Not all setters need to take an rvalue reference.&lt;/li&gt;
+&lt;li&gt;Forgetting to call WTF::move can result in unnecessary reference count churn.&lt;/li&gt;
+&lt;/ul&gt;
+
</ins><span class="cx"> &lt;h2&gt;Improving this document&lt;/h2&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;p&gt;We should add answers to any frequently asked questions are not covered by this document.
</span><span class="lines">@@ -372,31 +341,32 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;ul&gt;
</span><span class="cx"> 
</span><del>-&lt;li&gt;The “protector” idiom, where a local RefPtr variable is used to keep an object alive.&lt;/li&gt;
</del><ins>+&lt;li&gt;copyRef&lt;/li&gt;
+&lt;li&gt;releaseNonNull&lt;/li&gt;
</ins><span class="cx"> 
</span><del>-&lt;li&gt;Perils of programming with &lt;span class=&quot;class&quot;&gt;TreeShared&lt;/span&gt;.&lt;/li&gt;
</del><ins>+&lt;li&gt;How this works when these are stored in collections such as vectors and hash maps.&lt;/li&gt;
</ins><span class="cx"> 
</span><ins>+&lt;li&gt;Better explanation of when WTF::move is needed and not needed.&lt;/li&gt;
+
+&lt;li&gt;The “protector” idiom, where a local &lt;span class=&quot;class&quot;&gt;Ref&lt;/span&gt; variable is used to keep an object alive.&lt;/li&gt;
+
+&lt;li&gt;Perils of programming with &lt;span class=&quot;class&quot;&gt;TreeShared&lt;/span&gt;.
+(Or after we merge &lt;span class=&quot;class&quot;&gt;TreeShared&lt;/span&gt; into &lt;span class=&quot;class&quot;&gt;Node&lt;/span&gt;,
+the perils of programming with &lt;span class=&quot;class&quot;&gt;Node&lt;/span&gt;).&lt;/li&gt;
+
</ins><span class="cx"> &lt;li&gt;Our desire to eliminate &lt;span class=&quot;class&quot;&gt;TreeShared&lt;/span&gt; and instead have
</span><del>-&lt;span class=&quot;variable&quot;&gt;m_firstChild&lt;/span&gt; and &lt;span class=&quot;variable&quot;&gt;m_next&lt;/span&gt; be
-&lt;span class=&quot;class&quot;&gt;ListRefPtr&lt;/span&gt; or the equivalent.&lt;/li&gt;
</del><ins>+nodes hold a reference to their first child and next sibling.&lt;/li&gt;
</ins><span class="cx"> 
</span><span class="cx"> &lt;li&gt;How we we mix reference counting with garbage collection to implement the DOM
</span><span class="cx"> and the JavaScript and Objective-C DOM bindings.&lt;/li&gt;
</span><span class="cx"> 
</span><del>-&lt;li&gt;Comparison of our intrusive reference counting with other schemes such as the
-external reference counting in Boost &lt;span class=&quot;class&quot;&gt;shared_ptr&lt;/class&gt;.&lt;/li&gt;
</del><ins>+&lt;li&gt;Comparison of WebKit intrusive reference counting with other schemes such as the
+external reference counting in &lt;span class=&quot;class&quot;&gt;std::shared_ptr&lt;/class&gt;.&lt;/li&gt;
</ins><span class="cx"> 
</span><del>-&lt;li&gt;The &lt;span class=&quot;class&quot;&gt;OwnPtr&lt;/span&gt; class template, and how it can be used
-with &lt;span class=&quot;class&quot;&gt;PassOwnPtr&lt;/span&gt; and &lt;span class=&quot;function&quot;&gt;adoptPtr&lt;/span&gt;.&lt;/li&gt;
</del><ins>+&lt;li&gt;Guidelines for use of &lt;span class=&quot;class&quot;&gt;std::unique_ptr&lt;/span&gt; and &lt;span class=&quot;class&quot;&gt;std::make_unique&lt;/span&gt;.&lt;/li&gt;
</ins><span class="cx"> 
</span><del>-&lt;li&gt;The &lt;span class=&quot;class&quot;&gt;OwnArrayPtr&lt;/span&gt; class template,
-and &lt;span class=&quot;class&quot;&gt;PassOwnArrayPtr&lt;/span&gt;.&lt;/li&gt;
</del><ins>+&lt;li&gt;The &lt;span class=&quot;class&quot;&gt;RetainPtr&lt;/span&gt; class template.&lt;/li&gt;
</ins><span class="cx"> 
</span><del>-&lt;li&gt;The &lt;span class=&quot;class&quot;&gt;RetainPtr&lt;/span&gt; class template,
-and the lack of a &lt;span class=&quot;class&quot;&gt;PassRetainPtr&lt;/span&gt;.&lt;/li&gt;
-
-&lt;li&gt;The &lt;span class=&quot;class&quot;&gt;ListRefPtr&lt;/span&gt; class template.&lt;/li&gt;
-
</del><span class="cx"> &lt;/ul&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;p&gt;If you have any comments on the above or other ideas about improving the clarity,
</span></span></pre>
</div>
</div>

</body>
</html>