<!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>[174268] 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/174268">174268</a></dd>
<dt>Author</dt> <dd>weinig@apple.com</dd>
<dt>Date</dt> <dd>2014-10-03 09:47:06 -0700 (Fri, 03 Oct 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Remove RefPtrHashMap
https://bugs.webkit.org/show_bug.cgi?id=137200
Reviewed by Darin Adler.
Source/WTF:
HashMap now has all the features of the RefPtr specialization of HashMap
(which lived in RefPtrHashMap.h) and is in fact more efficient when moving
items into it. For instance:
For HashMap<RefPtr<Foo>, Bar> map:
RefPtr<Foo> foo = ...;
map.add(WTF::move(foo), Bar());
will now not cause a ref() / deref(), but will successfully move the item in
without churn. The same is true if foo.release() was used.
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
Remove references to RefPtrHashMap.h.
* wtf/RefPtrHashMap.h: Removed.
* wtf/HashMap.h:
Remove #include of RefPtrHashMap.h and add inlineGet to match the interface
exposed by the RefPtrHashMap specialization.
Tools:
* TestWebKitAPI/Tests/WTF/HashMap.cpp:
(TestWebKitAPI::TEST):
Add tests for using a HashMap with RefPtr keys, focusing on ensuring that
a minimum of refcount churn occurs.</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="#trunkSourceWTFwtfHashMaph">trunk/Source/WTF/wtf/HashMap.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFHashMapcpp">trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWTFwtfRefPtrHashMaph">trunk/Source/WTF/wtf/RefPtrHashMap.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Source/WTF/ChangeLog        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2014-09-28 Sam Weinig <sam@webkit.org>
+
+ Remove RefPtrHashMap
+ https://bugs.webkit.org/show_bug.cgi?id=137200
+
+ Reviewed by Darin Adler.
+
+ HashMap now has all the features of the RefPtr specialization of HashMap
+ (which lived in RefPtrHashMap.h) and is in fact more efficient when moving
+ items into it. For instance:
+
+ For HashMap<RefPtr<Foo>, Bar> map:
+
+ RefPtr<Foo> foo = ...;
+ map.add(WTF::move(foo), Bar());
+
+ will now not cause a ref() / deref(), but will successfully move the item in
+ without churn. The same is true if foo.release() was used.
+
+ * WTF.vcxproj/WTF.vcxproj:
+ * WTF.vcxproj/WTF.vcxproj.filters:
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/CMakeLists.txt:
+ Remove references to RefPtrHashMap.h.
+
+ * wtf/RefPtrHashMap.h: Removed.
+
+ * wtf/HashMap.h:
+ Remove #include of RefPtrHashMap.h and add inlineGet to match the interface
+ exposed by the RefPtrHashMap specialization.
+
</ins><span class="cx"> 2014-10-02 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Add back debugging/testing code that I accidentally removed.
</span></span></pre></div>
<a id="trunkSourceWTFWTFvcxprojWTFvcxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -257,7 +257,6 @@
</span><span class="cx"> <ClInclude Include="..\wtf\RefCounted.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\RefCountedLeakCounter.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\RefPtr.h" />
</span><del>- <ClInclude Include="..\wtf\RefPtrHashMap.h" />
</del><span class="cx"> <ClInclude Include="..\wtf\RetainPtr.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\RunLoop.h" />
</span><span class="cx"> <ClInclude Include="..\wtf\SaturatedArithmetic.h" />
</span></span></pre></div>
<a id="trunkSourceWTFWTFvcxprojWTFvcxprojfilters"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Source/WTF/WTF.vcxproj/WTF.vcxproj.filters        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -582,9 +582,6 @@
</span><span class="cx"> <ClInclude Include="..\wtf\RefPtr.h">
</span><span class="cx"> <Filter>wtf</Filter>
</span><span class="cx"> </ClInclude>
</span><del>- <ClInclude Include="..\wtf\RefPtrHashMap.h">
- <Filter>wtf</Filter>
- </ClInclude>
</del><span class="cx"> <ClInclude Include="..\wtf\RetainPtr.h">
</span><span class="cx"> <Filter>wtf</Filter>
</span><span class="cx"> </ClInclude>
</span></span></pre></div>
<a id="trunkSourceWTFWTFxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -205,7 +205,6 @@
</span><span class="cx">                 A8A4741A151A825B004123FF /* RefCountedLeakCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A47301151A825B004123FF /* RefCountedLeakCounter.cpp */; };
</span><span class="cx">                 A8A4741B151A825B004123FF /* RefCountedLeakCounter.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47302151A825B004123FF /* RefCountedLeakCounter.h */; };
</span><span class="cx">                 A8A4741C151A825B004123FF /* RefPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47303151A825B004123FF /* RefPtr.h */; };
</span><del>-                A8A4741D151A825B004123FF /* RefPtrHashMap.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47304151A825B004123FF /* RefPtrHashMap.h */; };
</del><span class="cx">                 A8A4741E151A825B004123FF /* RetainPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47305151A825B004123FF /* RetainPtr.h */; };
</span><span class="cx">                 A8A4741F151A825B004123FF /* SegmentedVector.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47306151A825B004123FF /* SegmentedVector.h */; };
</span><span class="cx">                 A8A47420151A825B004123FF /* SentinelLinkedList.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47307151A825B004123FF /* SentinelLinkedList.h */; };
</span><span class="lines">@@ -497,7 +496,6 @@
</span><span class="cx">                 A8A47301151A825B004123FF /* RefCountedLeakCounter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RefCountedLeakCounter.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 A8A47302151A825B004123FF /* RefCountedLeakCounter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCountedLeakCounter.h; sourceTree = "<group>"; };
</span><span class="cx">                 A8A47303151A825B004123FF /* RefPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefPtr.h; sourceTree = "<group>"; };
</span><del>-                A8A47304151A825B004123FF /* RefPtrHashMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefPtrHashMap.h; sourceTree = "<group>"; };
</del><span class="cx">                 A8A47305151A825B004123FF /* RetainPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RetainPtr.h; sourceTree = "<group>"; };
</span><span class="cx">                 A8A47306151A825B004123FF /* SegmentedVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SegmentedVector.h; sourceTree = "<group>"; };
</span><span class="cx">                 A8A47307151A825B004123FF /* SentinelLinkedList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SentinelLinkedList.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -831,7 +829,6 @@
</span><span class="cx">                                 A8A47301151A825B004123FF /* RefCountedLeakCounter.cpp */,
</span><span class="cx">                                 A8A47302151A825B004123FF /* RefCountedLeakCounter.h */,
</span><span class="cx">                                 A8A47303151A825B004123FF /* RefPtr.h */,
</span><del>-                                A8A47304151A825B004123FF /* RefPtrHashMap.h */,
</del><span class="cx">                                 A8A47305151A825B004123FF /* RetainPtr.h */,
</span><span class="cx">                                 2CDED0F118115C85004DBA70 /* RunLoop.cpp */,
</span><span class="cx">                                 2CDED0F218115C85004DBA70 /* RunLoop.h */,
</span><span class="lines">@@ -1153,7 +1150,6 @@
</span><span class="cx">                                 A8A47419151A825B004123FF /* RefCountedArray.h in Headers */,
</span><span class="cx">                                 A8A4741B151A825B004123FF /* RefCountedLeakCounter.h in Headers */,
</span><span class="cx">                                 A8A4741C151A825B004123FF /* RefPtr.h in Headers */,
</span><del>-                                A8A4741D151A825B004123FF /* RefPtrHashMap.h in Headers */,
</del><span class="cx">                                 A8A4741E151A825B004123FF /* RetainPtr.h in Headers */,
</span><span class="cx">                                 2CDED0F418115C85004DBA70 /* RunLoop.h in Headers */,
</span><span class="cx">                                 1469419216EAAF6D0024E146 /* RunLoopTimer.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWTFwtfCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/CMakeLists.txt (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/CMakeLists.txt        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Source/WTF/wtf/CMakeLists.txt        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -83,7 +83,6 @@
</span><span class="cx"> RefCounted.h
</span><span class="cx"> RefCountedLeakCounter.h
</span><span class="cx"> RefPtr.h
</span><del>- RefPtrHashMap.h
</del><span class="cx"> RetainPtr.h
</span><span class="cx"> RunLoop.h
</span><span class="cx"> SHA1.h
</span></span></pre></div>
<a id="trunkSourceWTFwtfHashMaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/HashMap.h (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/HashMap.h        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Source/WTF/wtf/HashMap.h        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -147,6 +147,7 @@
</span><span class="cx"> template<typename K = KeyType> typename std::enable_if<IsSmartPtr<K>::value, iterator>::type find(typename GetPtrHelper<K>::PtrType);
</span><span class="cx"> template<typename K = KeyType> typename std::enable_if<IsSmartPtr<K>::value, const_iterator>::type find(typename GetPtrHelper<K>::PtrType) const;
</span><span class="cx"> template<typename K = KeyType> typename std::enable_if<IsSmartPtr<K>::value, bool>::type contains(typename GetPtrHelper<K>::PtrType) const;
</span><ins>+ template<typename K = KeyType> typename std::enable_if<IsSmartPtr<K>::value, MappedPeekType>::type inlineGet(typename GetPtrHelper<K>::PtrType) const;
</ins><span class="cx"> template<typename K = KeyType> typename std::enable_if<IsSmartPtr<K>::value, MappedPeekType>::type get(typename GetPtrHelper<K>::PtrType) const;
</span><span class="cx"> template<typename K = KeyType> typename std::enable_if<IsSmartPtr<K>::value, bool>::type remove(typename GetPtrHelper<K>::PtrType);
</span><span class="cx"> template<typename K = KeyType> typename std::enable_if<IsSmartPtr<K>::value, MappedType>::type take(typename GetPtrHelper<K>::PtrType);
</span><span class="lines">@@ -416,7 +417,7 @@
</span><span class="cx">
</span><span class="cx"> template<typename T, typename U, typename V, typename W, typename X>
</span><span class="cx"> template<typename K>
</span><del>-inline auto HashMap<T, U, V, W, X>::get(typename GetPtrHelper<K>::PtrType key) const -> typename std::enable_if<IsSmartPtr<K>::value, MappedPeekType>::type
</del><ins>+inline auto HashMap<T, U, V, W, X>::inlineGet(typename GetPtrHelper<K>::PtrType key) const -> typename std::enable_if<IsSmartPtr<K>::value, MappedPeekType>::type
</ins><span class="cx"> {
</span><span class="cx"> KeyValuePairType* entry = const_cast<HashTableType&>(m_impl).template lookup<HashMapTranslator<KeyValuePairTraits, HashFunctions>>(key);
</span><span class="cx"> if (!entry)
</span><span class="lines">@@ -426,6 +427,13 @@
</span><span class="cx">
</span><span class="cx"> template<typename T, typename U, typename V, typename W, typename X>
</span><span class="cx"> template<typename K>
</span><ins>+auto HashMap<T, U, V, W, X>::get(typename GetPtrHelper<K>::PtrType key) const -> typename std::enable_if<IsSmartPtr<K>::value, MappedPeekType>::type
+{
+ return inlineGet(key);
+}
+
+template<typename T, typename U, typename V, typename W, typename X>
+template<typename K>
</ins><span class="cx"> inline auto HashMap<T, U, V, W, X>::remove(typename GetPtrHelper<K>::PtrType key) -> typename std::enable_if<IsSmartPtr<K>::value, bool>::type
</span><span class="cx"> {
</span><span class="cx"> return remove(find(key));
</span><span class="lines">@@ -521,6 +529,4 @@
</span><span class="cx">
</span><span class="cx"> using WTF::HashMap;
</span><span class="cx">
</span><del>-#include <wtf/RefPtrHashMap.h>
-
</del><span class="cx"> #endif /* WTF_HashMap_h */
</span></span></pre></div>
<a id="trunkSourceWTFwtfRefPtrHashMaph"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WTF/wtf/RefPtrHashMap.h (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RefPtrHashMap.h        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Source/WTF/wtf/RefPtrHashMap.h        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -1,334 +0,0 @@
</span><del>-/*
- * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2013 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef RefPtrHashMap_h
-#define RefPtrHashMap_h
-
-namespace WTF {
-
- // This specialization is a copy of HashMap for use with RefPtr keys, with overloaded functions
- // to allow for lookup by pointer instead of RefPtr, avoiding ref-count churn.
-
- // FIXME: Find a way to do this with traits that doesn't require a copy of the HashMap template.
-
- template<typename T, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
- class HashMap<RefPtr<T>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg> {
- WTF_MAKE_FAST_ALLOCATED;
- private:
- typedef KeyTraitsArg KeyTraits;
- typedef MappedTraitsArg MappedTraits;
- typedef KeyValuePairHashTraits<KeyTraits, MappedTraits> ValueTraits;
-
- public:
- typedef typename KeyTraits::TraitType KeyType;
- typedef T* RawKeyType;
- typedef typename MappedTraits::TraitType MappedType;
- typedef typename ValueTraits::TraitType ValueType;
-
- private:
- typedef typename MappedTraits::PeekType MappedPeekType;
-
- typedef HashArg HashFunctions;
-
- typedef HashTable<KeyType, ValueType, KeyValuePairKeyExtractor<ValueType>,
- HashFunctions, ValueTraits, KeyTraits> HashTableType;
-
- typedef HashMapTranslator<ValueTraits, HashFunctions>
- Translator;
-
- public:
- typedef HashTableIteratorAdapter<HashTableType, ValueType> iterator;
- typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator;
- typedef typename HashTableType::AddResult AddResult;
-
- void swap(HashMap&);
-
- int size() const;
- int capacity() const;
- bool isEmpty() const;
-
- // iterators iterate over pairs of keys and values
- iterator begin();
- iterator end();
- const_iterator begin() const;
- const_iterator end() const;
-
- IteratorRange<typename iterator::Keys> keys() { return makeIteratorRange(begin().keys(), end().keys()); }
- const IteratorRange<typename const_iterator::Keys> keys() const { return makeIteratorRange(begin().keys(), end().keys()); }
-
- IteratorRange<typename iterator::Values> values() { return makeIteratorRange(begin().values(), end().values()); }
- const IteratorRange<typename const_iterator::Values> values() const { return makeIteratorRange(begin().values(), end().values()); }
-
- iterator find(const KeyType&);
- iterator find(RawKeyType);
- const_iterator find(const KeyType&) const;
- const_iterator find(RawKeyType) const;
- bool contains(const KeyType&) const;
- bool contains(RawKeyType) const;
- MappedPeekType get(const KeyType&) const;
- MappedPeekType get(RawKeyType) const;
- MappedPeekType inlineGet(RawKeyType) const;
-
- // replaces value but not key if key is already present
- // return value is a pair of the iterator to the key location,
- // and a boolean that's true if a new value was actually added
- template<typename V> AddResult set(const KeyType&, V&&);
- template<typename V> AddResult set(RawKeyType, V&&);
-
- // does nothing if key is already present
- // return value is a pair of the iterator to the key location,
- // and a boolean that's true if a new value was actually added
- template<typename V> AddResult add(const KeyType&, V&&);
- template<typename V> AddResult add(RawKeyType, V&&);
-
- bool remove(const KeyType&);
- bool remove(RawKeyType);
- bool remove(iterator);
- void clear();
-
- MappedType take(const KeyType&); // efficient combination of get with remove
- MappedType take(RawKeyType); // efficient combination of get with remove
-
- private:
- template<typename V>
- AddResult inlineAdd(const KeyType&, V&&);
-
- template<typename V>
- AddResult inlineAdd(RawKeyType, V&&);
-
- HashTableType m_impl;
- };
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline void HashMap<RefPtr<T>, U, V, W, X>::swap(HashMap& other)
- {
- m_impl.swap(other.m_impl);
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline int HashMap<RefPtr<T>, U, V, W, X>::size() const
- {
- return m_impl.size();
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline int HashMap<RefPtr<T>, U, V, W, X>::capacity() const
- {
- return m_impl.capacity();
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline bool HashMap<RefPtr<T>, U, V, W, X>::isEmpty() const
- {
- return m_impl.isEmpty();
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::begin()
- {
- return m_impl.begin();
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::end()
- {
- return m_impl.end();
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::begin() const
- {
- return m_impl.begin();
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::end() const
- {
- return m_impl.end();
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::find(const KeyType& key)
- {
- return m_impl.find(key);
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::iterator HashMap<RefPtr<T>, U, V, W, X>::find(RawKeyType key)
- {
- return m_impl.template find<Translator>(key);
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::find(const KeyType& key) const
- {
- return m_impl.find(key);
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline typename HashMap<RefPtr<T>, U, V, W, X>::const_iterator HashMap<RefPtr<T>, U, V, W, X>::find(RawKeyType key) const
- {
- return m_impl.template find<Translator>(key);
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline bool HashMap<RefPtr<T>, U, V, W, X>::contains(const KeyType& key) const
- {
- return m_impl.contains(key);
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline bool HashMap<RefPtr<T>, U, V, W, X>::contains(RawKeyType key) const
- {
- return m_impl.template contains<Translator>(key);
- }
-
- template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
- template<typename V>
- auto HashMap<RefPtr<KeyArg>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineAdd(const KeyType& key, V&& mapped) -> AddResult
- {
- return m_impl.template add<Translator>(key, std::forward<V>(mapped));
- }
-
- template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
- template<typename V>
- auto HashMap<RefPtr<KeyArg>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::inlineAdd(RawKeyType key, V&& mapped) -> AddResult
- {
- return m_impl.template add<Translator>(key, std::forward<V>(mapped));
- }
-
- template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
- template<typename V>
- auto HashMap<RefPtr<KeyArg>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::set(const KeyType& key, V&& value) -> AddResult
- {
- AddResult result = inlineAdd(key, std::forward<V>(value));
- if (!result.isNewEntry) {
- // The inlineAdd call above found an existing hash table entry; we need to set the mapped value.
- result.iterator->value = std::forward<V>(value);
- }
- return result;
- }
-
- template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
- template<typename V>
- auto HashMap<RefPtr<KeyArg>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::set(RawKeyType key, V&& value) -> AddResult
- {
- AddResult result = inlineAdd(key, std::forward<V>(value));
- if (!result.isNewEntry) {
- // The inlineAdd call above found an existing hash table entry; we need to set the mapped value.
- result.iterator->value = std::forward<V>(value);
- }
- return result;
- }
-
- template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
- template<typename V>
- auto HashMap<RefPtr<KeyArg>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::add(const KeyType& key, V&& value) -> AddResult
- {
- return inlineAdd(key, std::forward<V>(value));
- }
-
- template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg>
- template<typename V>
- auto HashMap<RefPtr<KeyArg>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::add(RawKeyType key, V&& value) -> AddResult
- {
- return inlineAdd(key, std::forward<V>(value));
- }
-
- template<typename T, typename U, typename V, typename W, typename MappedTraits>
- typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedPeekType
- HashMap<RefPtr<T>, U, V, W, MappedTraits>::get(const KeyType& key) const
- {
- ValueType* entry = const_cast<HashTableType&>(m_impl).lookup(key);
- if (!entry)
- return MappedTraits::peek(MappedTraits::emptyValue());
- return MappedTraits::peek(entry->value);
- }
-
- template<typename T, typename U, typename V, typename W, typename MappedTraits>
- typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedPeekType
- inline HashMap<RefPtr<T>, U, V, W, MappedTraits>::inlineGet(RawKeyType key) const
- {
- ValueType* entry = const_cast<HashTableType&>(m_impl).template lookup<Translator>(key);
- if (!entry)
- return MappedTraits::peek(MappedTraits::emptyValue());
- return MappedTraits::peek(entry->value);
- }
-
- template<typename T, typename U, typename V, typename W, typename MappedTraits>
- typename HashMap<RefPtr<T>, U, V, W, MappedTraits>::MappedPeekType
- HashMap<RefPtr<T>, U, V, W, MappedTraits>::get(RawKeyType key) const
- {
- return inlineGet(key);
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline bool HashMap<RefPtr<T>, U, V, W, X>::remove(iterator it)
- {
- if (it.m_impl == m_impl.end())
- return false;
- m_impl.internalCheckTableConsistency();
- m_impl.removeWithoutEntryConsistencyCheck(it.m_impl);
- return true;
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline bool HashMap<RefPtr<T>, U, V, W, X>::remove(const KeyType& key)
- {
- return remove(find(key));
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline bool HashMap<RefPtr<T>, U, V, W, X>::remove(RawKeyType key)
- {
- return remove(find(key));
- }
-
- template<typename T, typename U, typename V, typename W, typename X>
- inline void HashMap<RefPtr<T>, U, V, W, X>::clear()
- {
- m_impl.clear();
- }
-
- template<typename T, typename U, typename V, typename W, typename MappedTraits>
- auto HashMap<RefPtr<T>, U, V, W, MappedTraits>::take(const KeyType& key) -> MappedType
- {
- iterator it = find(key);
- if (it == end())
- return MappedTraits::emptyValue();
- MappedType value = WTF::move(it->value);
- remove(it);
- return value;
- }
-
- template<typename T, typename U, typename V, typename W, typename MappedTraits>
- auto HashMap<RefPtr<T>, U, V, W, MappedTraits>::take(RawKeyType key) -> MappedType
- {
- iterator it = find(key);
- if (it == end())
- return MappedTraits::emptyValue();
- MappedType value = WTF::move(it->value);
- remove(it);
- return value;
- }
-
-} // namespace WTF
-
-#endif // RefPtrHashMap_h
</del></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Tools/ChangeLog        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-09-28 Sam Weinig <sam@webkit.org>
+
+ Remove RefPtrHashMap
+ https://bugs.webkit.org/show_bug.cgi?id=137200
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WTF/HashMap.cpp:
+ (TestWebKitAPI::TEST):
+ Add tests for using a HashMap with RefPtr keys, focusing on ensuring that
+ a minimum of refcount churn occurs.
+
</ins><span class="cx"> 2014-10-03 Eva Balazsfalvi <evab.u-szeged@partner.samsung.com>
</span><span class="cx">
</span><span class="cx"> Remove workarounds for versions of Python before 2.7
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFHashMapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp (174267 => 174268)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp        2014-10-03 16:43:06 UTC (rev 174267)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp        2014-10-03 16:47:06 UTC (rev 174268)
</span><span class="lines">@@ -27,11 +27,12 @@
</span><span class="cx">
</span><span class="cx"> #include "Counters.h"
</span><span class="cx"> #include "MoveOnly.h"
</span><ins>+#include "RefLogger.h"
</ins><span class="cx"> #include <string>
</span><span class="cx"> #include <wtf/HashMap.h>
</span><del>-#include <wtf/text/StringHash.h>
</del><span class="cx"> #include <wtf/OwnPtr.h>
</span><span class="cx"> #include <wtf/PassOwnPtr.h>
</span><ins>+#include <wtf/text/StringHash.h>
</ins><span class="cx">
</span><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx">
</span><span class="lines">@@ -386,4 +387,222 @@
</span><span class="cx"> EXPECT_EQ(1u, ConstructorDestructorCounter::destructionCount);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+TEST(WTF_HashMap, RefPtrKey_Add)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.add(ptr, 0);
+
+ ASSERT_STREQ("ref(a) ref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_AddUsingRelease)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.add(ptr.release(), 0);
+
+ EXPECT_STREQ("ref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_AddUsingMove)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.add(WTF::move(ptr), 0);
+
+ EXPECT_STREQ("ref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_AddUsingRaw)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.add(ptr.get(), 0);
+
+ EXPECT_STREQ("ref(a) ref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_AddKeyAlreadyPresent)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ map.add(ptr, 0);
+ }
+
+ EXPECT_STREQ("ref(a) ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr2(&a);
+ auto addResult = map.add(ptr2, 0);
+ EXPECT_EQ(false, addResult.isNewEntry);
+ }
+
+ EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_AddUsingReleaseKeyAlreadyPresent)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ map.add(ptr, 0);
+ }
+
+ EXPECT_STREQ("ref(a) ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr2(&a);
+ auto addResult = map.add(ptr2.release(), 0);
+ EXPECT_EQ(false, addResult.isNewEntry);
+ }
+
+ EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_AddUsingMoveKeyAlreadyPresent)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+
+ {
+ RefPtr<RefLogger> ptr(&a);
+ map.add(ptr, 0);
+ }
+
+ EXPECT_STREQ("ref(a) ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr2(&a);
+ auto addResult = map.add(WTF::move(ptr2), 0);
+ EXPECT_EQ(false, addResult.isNewEntry);
+ }
+
+ EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_Set)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.set(ptr, 0);
+
+ ASSERT_STREQ("ref(a) ref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_SetUsingRelease)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.set(ptr.release(), 0);
+
+ EXPECT_STREQ("ref(a) ", takeLogStr().c_str());
+}
+
+
+TEST(WTF_HashMap, RefPtrKey_SetUsingMove)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.set(WTF::move(ptr), 0);
+
+ EXPECT_STREQ("ref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_SetUsingRaw)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+ RefPtr<RefLogger> ptr(&a);
+ map.set(ptr.get(), 0);
+
+ EXPECT_STREQ("ref(a) ref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_SetKeyAlreadyPresent)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+
+ RefPtr<RefLogger> ptr(&a);
+ map.set(ptr, 0);
+
+ EXPECT_STREQ("ref(a) ref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr2(&a);
+ auto addResult = map.set(ptr2, 1);
+ EXPECT_EQ(false, addResult.isNewEntry);
+ EXPECT_EQ(1, map.get(ptr.get()));
+ }
+
+ EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_SetUsingReleaseKeyAlreadyPresent)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+
+ RefPtr<RefLogger> ptr(&a);
+ map.set(ptr, 0);
+
+ EXPECT_STREQ("ref(a) ref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr2(&a);
+ auto addResult = map.set(ptr2.release(), 1);
+ EXPECT_EQ(false, addResult.isNewEntry);
+ EXPECT_EQ(1, map.get(ptr.get()));
+ }
+
+ EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
+TEST(WTF_HashMap, RefPtrKey_SetUsingMoveKeyAlreadyPresent)
+{
+ HashMap<RefPtr<RefLogger>, int> map;
+
+ DerivedRefLogger a("a");
+
+ RefPtr<RefLogger> ptr(&a);
+ map.set(ptr, 0);
+
+ EXPECT_STREQ("ref(a) ref(a) ", takeLogStr().c_str());
+
+ {
+ RefPtr<RefLogger> ptr2(&a);
+ auto addResult = map.set(WTF::move(ptr2), 1);
+ EXPECT_EQ(false, addResult.isNewEntry);
+ EXPECT_EQ(1, map.get(ptr.get()));
+ }
+
+ EXPECT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span></span></pre>
</div>
</div>
</body>
</html>