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

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

<h3>Log Message</h3>
<pre>We should be able to use std::tuples as keys in HashMap
https://bugs.webkit.org/show_bug.cgi?id=168805

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

Convert the mess of std::pairs we used as the keys in PrototypeMap
to a std::tuple. I also plan on using this for a HashMap in wasm.

* JavaScriptCore.xcodeproj/project.pbxproj:
* runtime/PrototypeMap.cpp:
(JSC::PrototypeMap::createEmptyStructure):
(JSC::PrototypeMap::clearEmptyObjectStructureForPrototype):
* runtime/PrototypeMap.h:

Source/WTF:

This patch adds support for using std::tupeles as the key
type in HashMap. It is equivalent to doing a sequence of
std::pairs but has a nicer syntax.

* wtf/HashFunctions.h:
(WTF::TupleHash::hash):
(WTF::TupleHash::equal):
(WTF::TupleHash::allTrue):
* wtf/HashTraits.h:
(WTF::TupleHashTraits::allTrue):
(WTF::TupleHashTraits::emptyValue):
(WTF::TupleHashTraits::constructDeletedValue):
(WTF::TupleHashTraits::isDeletedValue):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj">trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimePrototypeMapcpp">trunk/Source/JavaScriptCore/runtime/PrototypeMap.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimePrototypeMaph">trunk/Source/JavaScriptCore/runtime/PrototypeMap.h</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfHashFunctionsh">trunk/Source/WTF/wtf/HashFunctions.h</a></li>
<li><a href="#trunkSourceWTFwtfHashTraitsh">trunk/Source/WTF/wtf/HashTraits.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (212968 => 212969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2017-02-24 20:44:41 UTC (rev 212968)
+++ trunk/Source/JavaScriptCore/ChangeLog        2017-02-24 22:14:38 UTC (rev 212969)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2017-02-24  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        We should be able to use std::tuples as keys in HashMap
+        https://bugs.webkit.org/show_bug.cgi?id=168805
+
+        Reviewed by Filip Pizlo.
+
+        Convert the mess of std::pairs we used as the keys in PrototypeMap
+        to a std::tuple. I also plan on using this for a HashMap in wasm.
+
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * runtime/PrototypeMap.cpp:
+        (JSC::PrototypeMap::createEmptyStructure):
+        (JSC::PrototypeMap::clearEmptyObjectStructureForPrototype):
+        * runtime/PrototypeMap.h:
+
</ins><span class="cx"> 2017-02-24  Saam Barati  &lt;sbarati@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Remove inaccurate copy-paste comment from r212939.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreJavaScriptCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (212968 => 212969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2017-02-24 20:44:41 UTC (rev 212968)
+++ trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj        2017-02-24 22:14:38 UTC (rev 212969)
</span><span class="lines">@@ -1262,6 +1262,7 @@
</span><span class="cx">                 2AF7382C18BBBF92008A5A37 /* StructureIDTable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AF7382A18BBBF92008A5A37 /* StructureIDTable.cpp */; };
</span><span class="cx">                 2AF7382D18BBBF92008A5A37 /* StructureIDTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AF7382B18BBBF92008A5A37 /* StructureIDTable.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 2D342F36F7244096804ADB24 /* SourceOrigin.h in Headers */ = {isa = PBXBuildFile; fileRef = 425BA1337E4344E1B269A671 /* SourceOrigin.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><ins>+                321D9E4CFB67423A97F191A7 /* ModuleNamespaceAccessCase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20ECB15EFC524624BC2F02D5 /* ModuleNamespaceAccessCase.cpp */; };
</ins><span class="cx">                 371D842D17C98B6E00ECF994 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 371D842C17C98B6E00ECF994 /* libz.dylib */; };
</span><span class="cx">                 412952771D2CF6BC00E78B89 /* builtins_generate_internals_wrapper_header.py in Headers */ = {isa = PBXBuildFile; fileRef = 412952731D2CF6AC00E78B89 /* builtins_generate_internals_wrapper_header.py */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 412952781D2CF6BC00E78B89 /* builtins_generate_internals_wrapper_implementation.py in Headers */ = {isa = PBXBuildFile; fileRef = 412952741D2CF6AC00E78B89 /* builtins_generate_internals_wrapper_implementation.py */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -1673,6 +1674,7 @@
</span><span class="cx">                 9E729407190F01A5001A91B5 /* InitializeThreading.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E178636C0D9BEEC300D74E75 /* InitializeThreading.cpp */; };
</span><span class="cx">                 9E72940B190F0514001A91B5 /* BundlePath.h in Headers */ = {isa = PBXBuildFile; fileRef = 9E72940A190F0514001A91B5 /* BundlePath.h */; };
</span><span class="cx">                 9EA5C7A1190F084200508EBE /* BundlePath.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9E729409190F0306001A91B5 /* BundlePath.mm */; };
</span><ins>+                9F63434577274FAFB9336C38 /* ModuleNamespaceAccessCase.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CE978E385A8498199052153 /* ModuleNamespaceAccessCase.h */; };
</ins><span class="cx">                 A125846E1B45A36000CC7F6C /* IntlNumberFormatConstructor.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = A125846C1B45A36000CC7F6C /* IntlNumberFormatConstructor.lut.h */; };
</span><span class="cx">                 A125846F1B45A36000CC7F6C /* IntlNumberFormatPrototype.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = A125846D1B45A36000CC7F6C /* IntlNumberFormatPrototype.lut.h */; };
</span><span class="cx">                 A12BBFF21B044A8B00664B69 /* IntlObject.h in Headers */ = {isa = PBXBuildFile; fileRef = A12BBFF11B044A8B00664B69 /* IntlObject.h */; };
</span><span class="lines">@@ -2413,8 +2415,6 @@
</span><span class="cx">                 FED94F2F171E3E2300BE77A4 /* Watchdog.h in Headers */ = {isa = PBXBuildFile; fileRef = FED94F2C171E3E2300BE77A4 /* Watchdog.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 FEF040511AAE662D00BD28B0 /* CompareAndSwapTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEF040501AAE662D00BD28B0 /* CompareAndSwapTest.cpp */; };
</span><span class="cx">                 FEFD6FC61D5E7992008F2F0B /* JSStringInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><del>-                321D9E4CFB67423A97F191A7 /* ModuleNamespaceAccessCase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20ECB15EFC524624BC2F02D5 /* ModuleNamespaceAccessCase.cpp */; };
-                9F63434577274FAFB9336C38 /* ModuleNamespaceAccessCase.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CE978E385A8498199052153 /* ModuleNamespaceAccessCase.h */; };
</del><span class="cx"> /* End PBXBuildFile section */
</span><span class="cx"> 
</span><span class="cx"> /* Begin PBXContainerItemProxy section */
</span><span class="lines">@@ -3683,6 +3683,7 @@
</span><span class="cx">                 1C9051450BA9E8A70081E9D0 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1CAA8B4A0D32C39A0041BCFF /* JavaScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScript.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1CAA8B4B0D32C39A0041BCFF /* JavaScriptCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptCore.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                20ECB15EFC524624BC2F02D5 /* ModuleNamespaceAccessCase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModuleNamespaceAccessCase.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 2600B5A4152BAAA70091EE5F /* JSStringJoiner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSStringJoiner.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 2600B5A5152BAAA70091EE5F /* JSStringJoiner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringJoiner.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 262D85B41C0D650F006ACB61 /* AirFixPartialRegisterStalls.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AirFixPartialRegisterStalls.cpp; path = b3/air/AirFixPartialRegisterStalls.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -3736,6 +3737,7 @@
</span><span class="cx">                 449097EE0F8F81B50076A327 /* FeatureDefines.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = FeatureDefines.xcconfig; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 451539B812DC994500EF7AC4 /* Yarr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Yarr.h; path = yarr/Yarr.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 45E12D8806A49B0F00E9DF84 /* jsc.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jsc.cpp; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 4; };
</span><ins>+                4CE978E385A8498199052153 /* ModuleNamespaceAccessCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleNamespaceAccessCase.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = &quot;&lt;absolute&gt;&quot;; };
</span><span class="cx">                 51F0EC0705C86C9A00E6DF1B /* libobjc.dylib */ = {isa = PBXFileReference; lastKnownFileType = &quot;compiled.mach-o.dylib&quot;; name = libobjc.dylib; path = /usr/lib/libobjc.dylib; sourceTree = &quot;&lt;absolute&gt;&quot;; };
</span><span class="cx">                 52678F8C1A031009006A306D /* BasicBlockLocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BasicBlockLocation.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -4984,8 +4986,6 @@
</span><span class="cx">                 FEF040501AAE662D00BD28B0 /* CompareAndSwapTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CompareAndSwapTest.cpp; path = API/tests/CompareAndSwapTest.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 FEF040521AAEC4ED00BD28B0 /* CompareAndSwapTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CompareAndSwapTest.h; path = API/tests/CompareAndSwapTest.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringInlines.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                20ECB15EFC524624BC2F02D5 /* ModuleNamespaceAccessCase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ModuleNamespaceAccessCase.cpp; path = ModuleNamespaceAccessCase.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
-                4CE978E385A8498199052153 /* ModuleNamespaceAccessCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ModuleNamespaceAccessCase.h; path = ModuleNamespaceAccessCase.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><span class="cx"> /* End PBXFileReference section */
</span><span class="cx"> 
</span><span class="cx"> /* Begin PBXFrameworksBuildPhase section */
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimePrototypeMapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/PrototypeMap.cpp (212968 => 212969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/PrototypeMap.cpp        2017-02-24 20:44:41 UTC (rev 212968)
+++ trunk/Source/JavaScriptCore/runtime/PrototypeMap.cpp        2017-02-24 22:14:38 UTC (rev 212969)
</span><span class="lines">@@ -56,7 +56,7 @@
</span><span class="cx"> 
</span><span class="cx"> inline Structure* PrototypeMap::createEmptyStructure(JSGlobalObject* globalObject, JSObject* prototype, const TypeInfo&amp; typeInfo, const ClassInfo* classInfo, IndexingType indexingType, unsigned inlineCapacity)
</span><span class="cx"> {
</span><del>-    auto key = std::make_pair(prototype, std::make_pair(inlineCapacity, std::make_pair(classInfo, globalObject)));
</del><ins>+    auto key = std::make_tuple(prototype, inlineCapacity, classInfo, globalObject);
</ins><span class="cx">     if (Structure* structure = m_structures.get(key)) {
</span><span class="cx">         ASSERT(isPrototype(prototype));
</span><span class="cx">         return structure;
</span><span class="lines">@@ -86,7 +86,7 @@
</span><span class="cx"> 
</span><span class="cx"> void PrototypeMap::clearEmptyObjectStructureForPrototype(JSGlobalObject* globalObject, JSObject* object, unsigned inlineCapacity)
</span><span class="cx"> {
</span><del>-    m_structures.remove(std::make_pair(object, std::make_pair(inlineCapacity, std::make_pair(JSFinalObject::info(), globalObject))));
</del><ins>+    m_structures.remove(std::make_tuple(object, inlineCapacity, JSFinalObject::info(), globalObject));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimePrototypeMaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/PrototypeMap.h (212968 => 212969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/PrototypeMap.h        2017-02-24 20:44:41 UTC (rev 212968)
+++ trunk/Source/JavaScriptCore/runtime/PrototypeMap.h        2017-02-24 22:14:38 UTC (rev 212969)
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx"> 
</span><span class="cx">     WeakGCMap&lt;JSObject*, JSObject&gt; m_prototypes;
</span><span class="cx">     // FIXME: make the key a struct.
</span><del>-    typedef WeakGCMap&lt;std::pair&lt;JSObject*, std::pair&lt;unsigned, std::pair&lt;const ClassInfo*, JSGlobalObject*&gt;&gt;&gt;, Structure&gt; StructureMap;
</del><ins>+    typedef WeakGCMap&lt;std::tuple&lt;JSObject*, unsigned, const ClassInfo*, JSGlobalObject*&gt;, Structure&gt; StructureMap;
</ins><span class="cx">     StructureMap m_structures;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (212968 => 212969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2017-02-24 20:44:41 UTC (rev 212968)
+++ trunk/Source/WTF/ChangeLog        2017-02-24 22:14:38 UTC (rev 212969)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2017-02-24  Keith Miller  &lt;keith_miller@apple.com&gt;
+
+        We should be able to use std::tuples as keys in HashMap
+        https://bugs.webkit.org/show_bug.cgi?id=168805
+
+        Reviewed by Filip Pizlo.
+
+        This patch adds support for using std::tupeles as the key
+        type in HashMap. It is equivalent to doing a sequence of
+        std::pairs but has a nicer syntax.
+
+        * wtf/HashFunctions.h:
+        (WTF::TupleHash::hash):
+        (WTF::TupleHash::equal):
+        (WTF::TupleHash::allTrue):
+        * wtf/HashTraits.h:
+        (WTF::TupleHashTraits::allTrue):
+        (WTF::TupleHashTraits::emptyValue):
+        (WTF::TupleHashTraits::constructDeletedValue):
+        (WTF::TupleHashTraits::isDeletedValue):
+
</ins><span class="cx"> 2017-02-24  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Prepare to enable WebRTC on iOS
</span></span></pre></div>
<a id="trunkSourceWTFwtfHashFunctionsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/HashFunctions.h (212968 => 212969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/HashFunctions.h        2017-02-24 20:44:41 UTC (rev 212968)
+++ trunk/Source/WTF/wtf/HashFunctions.h        2017-02-24 22:14:38 UTC (rev 212969)
</span><span class="lines">@@ -175,6 +175,45 @@
</span><span class="cx">         static const bool safeToCompareToEmptyOrDeleted = PairHash&lt;T, U&gt;::safeToCompareToEmptyOrDeleted;
</span><span class="cx">     };
</span><span class="cx"> 
</span><ins>+    template&lt;typename... Types&gt;
+    struct TupleHash {
+        template&lt;size_t I = 0&gt;
+        static typename std::enable_if&lt;I &lt; sizeof...(Types) - 1, unsigned&gt;::type hash(const std::tuple&lt;Types...&gt;&amp; t)
+        {
+            using IthTupleElementType = typename std::tuple_element&lt;I, typename std::tuple&lt;Types...&gt;&gt;::type;
+            return pairIntHash(DefaultHash&lt;IthTupleElementType&gt;::Hash::hash(std::get&lt;I&gt;(t)), hash&lt;I + 1&gt;(t));
+        }
+
+        template&lt;size_t I = 0&gt;
+        static typename std::enable_if&lt;I == sizeof...(Types) - 1, unsigned&gt;::type hash(const std::tuple&lt;Types...&gt;&amp; t)
+        {
+            using IthTupleElementType = typename std::tuple_element&lt;I, typename std::tuple&lt;Types...&gt;&gt;::type;
+            return DefaultHash&lt;IthTupleElementType&gt;::Hash::hash(std::get&lt;I&gt;(t));
+        }
+
+        template&lt;size_t I = 0&gt;
+        static typename std::enable_if&lt;I &lt; sizeof...(Types) - 1, bool&gt;::type equal(const std::tuple&lt;Types...&gt;&amp; a, const std::tuple&lt;Types...&gt;&amp; b)
+        {
+            using IthTupleElementType = typename std::tuple_element&lt;I, typename std::tuple&lt;Types...&gt;&gt;::type;
+            return DefaultHash&lt;IthTupleElementType&gt;::Hash::equal(std::get&lt;I&gt;(a), std::get&lt;I&gt;(b)) &amp;&amp; equal&lt;I + 1&gt;(a, b);
+        }
+
+        template&lt;size_t I = 0&gt;
+        static typename std::enable_if&lt;I == sizeof...(Types) - 1, bool&gt;::type equal(const std::tuple&lt;Types...&gt;&amp; a, const std::tuple&lt;Types...&gt;&amp; b)
+        {
+            using IthTupleElementType = typename std::tuple_element&lt;I, typename std::tuple&lt;Types...&gt;&gt;::type;
+            return DefaultHash&lt;IthTupleElementType&gt;::Hash::equal(std::get&lt;I&gt;(a), std::get&lt;I&gt;(b));
+        }
+
+        // We should use safeToCompareToEmptyOrDeleted = DefaultHash&lt;Types&gt;::Hash::safeToCompareToEmptyOrDeleted &amp;&amp;... whenever
+        // we switch to C++17. We can't do anything better here right now because GCC can't do C++.
+        template&lt;typename Bool&gt;
+        static constexpr bool allTrue(Bool value) { return value; }
+        template&lt;typename Bool, typename... Bools&gt;
+        static constexpr bool allTrue(Bool value, Bools... values) { return value &amp;&amp; allTrue(values...); }
+        static const bool safeToCompareToEmptyOrDeleted = allTrue(DefaultHash&lt;Types&gt;::Hash::safeToCompareToEmptyOrDeleted...);
+    };
+
</ins><span class="cx">     // make IntHash the default hash function for many integer types
</span><span class="cx"> 
</span><span class="cx">     template&lt;&gt; struct DefaultHash&lt;bool&gt; { typedef IntHash&lt;uint8_t&gt; Hash; };
</span><span class="lines">@@ -224,6 +263,7 @@
</span><span class="cx">     // make PairHash the default hash function for pairs of arbitrary values.
</span><span class="cx"> 
</span><span class="cx">     template&lt;typename T, typename U&gt; struct DefaultHash&lt;std::pair&lt;T, U&gt;&gt; { typedef PairHash&lt;T, U&gt; Hash; };
</span><ins>+    template&lt;typename... Types&gt; struct DefaultHash&lt;std::tuple&lt;Types...&gt;&gt; { typedef TupleHash&lt;Types...&gt; Hash; };
</ins><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFwtfHashTraitsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/HashTraits.h (212968 => 212969)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/HashTraits.h        2017-02-24 20:44:41 UTC (rev 212968)
+++ trunk/Source/WTF/wtf/HashTraits.h        2017-02-24 22:14:38 UTC (rev 212969)
</span><span class="lines">@@ -256,6 +256,29 @@
</span><span class="cx"> template&lt;typename First, typename Second&gt;
</span><span class="cx"> struct HashTraits&lt;std::pair&lt;First, Second&gt;&gt; : public PairHashTraits&lt;HashTraits&lt;First&gt;, HashTraits&lt;Second&gt;&gt; { };
</span><span class="cx"> 
</span><ins>+template&lt;typename FirstTrait, typename... Traits&gt;
+struct TupleHashTraits : GenericHashTraits&lt;std::tuple&lt;typename FirstTrait::TraitType, typename Traits::TraitType...&gt;&gt; {
+    typedef std::tuple&lt;typename FirstTrait::TraitType, typename Traits::TraitType...&gt; TraitType;
+    typedef std::tuple&lt;typename FirstTrait::EmptyValueType, typename Traits::EmptyValueType...&gt; EmptyValueType;
+
+    // We should use emptyValueIsZero = Traits::emptyValueIsZero &amp;&amp;... whenever we switch to C++17. We can't do anything
+    // better here right now because GCC can't do C++.
+    template&lt;typename Bool&gt;
+    static constexpr bool allTrue(Bool value) { return value; }
+    template&lt;typename Bool, typename... Bools&gt;
+    static constexpr bool allTrue(Bool value, Bools... values) { return value &amp;&amp; allTrue(values...); }
+    static const bool emptyValueIsZero = allTrue(FirstTrait::emptyValueIsZero, Traits::emptyValueIsZero...);
+    static EmptyValueType emptyValue() { return std::make_tuple(FirstTrait::emptyValue(), Traits::emptyValue()...); }
+
+    static const unsigned minimumTableSize = FirstTrait::minimumTableSize;
+
+    static void constructDeletedValue(TraitType&amp; slot) { FirstTrait::constructDeletedValue(std::get&lt;0&gt;(slot)); }
+    static bool isDeletedValue(const TraitType&amp; value) { return FirstTrait::isDeletedValue(std::get&lt;0&gt;(value)); }
+};
+
+template&lt;typename... Traits&gt;
+struct HashTraits&lt;std::tuple&lt;Traits...&gt;&gt; : public TupleHashTraits&lt;HashTraits&lt;Traits&gt;...&gt; { };
+
</ins><span class="cx"> template&lt;typename KeyTypeArg, typename ValueTypeArg&gt;
</span><span class="cx"> struct KeyValuePair {
</span><span class="cx">     typedef KeyTypeArg KeyType;
</span></span></pre>
</div>
</div>

</body>
</html>