Bug 1475139 part 3 - Add serialization support for nsTHashtable with nsUint64HashKey. r=froydnj
authorRyan Hunt <rhunt@eqrion.net>
Mon, 24 Sep 2018 21:35:31 -0500
changeset 495729 ba9a0af62c4b60260cb90b7cc4673dec0e25fd7d
parent 495728 766131a8c0a9a8361c313b45f28ae8262af3dd8a
child 495730 0b5334e2a28479aa2df0c75c3c15cb1e6ba4cab8
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1475139
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1475139 part 3 - Add serialization support for nsTHashtable with nsUint64HashKey. r=froydnj I'd like to use a nsTHashtable acting as a set in a struct that will be passed over IPDL, but couldn't find any ParamTraits implementation for it. It'd be nice to make the implementation generic, but I couldn't find an easy way to do it. Differential Revision: https://phabricator.services.mozilla.com/D6782
ipc/glue/IPCMessageUtils.h
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -25,21 +25,23 @@
 #include "mozilla/TypeTraits.h"
 #include "mozilla/IntegerTypeTraits.h"
 
 #include <limits>
 #include <stdint.h>
 #include <type_traits>
 
 #include "nsExceptionHandler.h"
+#include "nsHashKeys.h"
 #include "nsID.h"
 #include "nsIWidget.h"
 #include "nsMemory.h"
 #include "nsString.h"
 #include "nsTArray.h"
+#include "nsTHashtable.h"
 #include "js/StructuredClone.h"
 #include "nsCSSPropertyID.h"
 
 #ifdef _MSC_VER
 #pragma warning( disable : 4800 )
 #endif
 
 #if !defined(OS_POSIX)
@@ -532,16 +534,49 @@ struct ParamTraits<nsDependentCSubstring
 template<>
 struct ParamTraits<nsAutoString> : ParamTraits<nsString>
 {
   typedef nsAutoString paramType;
 };
 
 #endif  // MOZILLA_INTERNAL_API
 
+template <>
+struct ParamTraits<nsTHashtable<nsUint64HashKey>>
+{
+  typedef nsTHashtable<nsUint64HashKey> paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    uint32_t count = aParam.Count();
+    WriteParam(aMsg, count);
+    for (auto iter = aParam.ConstIter(); !iter.Done(); iter.Next()) {
+      WriteParam(aMsg, iter.Get()->GetKey());
+    }
+  }
+
+  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
+  {
+    uint32_t count;
+    if (!ReadParam(aMsg, aIter, &count)) {
+      return false;
+    }
+    paramType table(count);
+    for (uint32_t i = 0; i < count; ++i) {
+      uint64_t key;
+      if (!ReadParam(aMsg, aIter, &key)) {
+        return false;
+      }
+      table.PutEntry(key);
+    }
+    *aResult = std::move(table);
+    return true;
+  }
+};
+
 // Pickle::ReadBytes and ::WriteBytes take the length in ints, so we must
 // ensure there is no overflow. This returns |false| if it would overflow.
 // Otherwise, it returns |true| and places the byte length in |aByteLength|.
 bool ByteLengthIsValid(uint32_t aNumElements, size_t aElementSize, int* aByteLength);
 
 // Note: IPDL will sometimes codegen specialized implementations of
 // nsTArray serialization and deserialization code in
 // implementSpecialArrayPickling(). This is needed when ParamTraits<E>