Bug 1253476 - Add DefaultHasher implementation for OwningAnimationTarget; r=njn
authorBrian Birtles <birtles@gmail.com>
Mon, 20 May 2019 05:22:07 +0000
changeset 474486 a80ca3b22049b0a8a4cf7f8a8c1e3291d434ef3e
parent 474485 0e25f7b0790b67bcd5614384def4f7158aa3048f
child 474487 f0273e0339381e099a35aef2ae6a65fe3149e415
push id36040
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:43:21 +0000
treeherdermozilla-central@319a369ccde4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1253476
milestone68.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 1253476 - Add DefaultHasher implementation for OwningAnimationTarget; r=njn Later in this patch series we will add a HashSet<OwningAnimationTarget> member to EffectCompositor. This patch provides the necessary definitions to support that. Differential Revision: https://phabricator.services.mozilla.com/D30320
dom/animation/AnimationTarget.h
--- a/dom/animation/AnimationTarget.h
+++ b/dom/animation/AnimationTarget.h
@@ -2,17 +2,19 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_AnimationTarget_h
 #define mozilla_AnimationTarget_h
 
-#include "mozilla/Attributes.h"  // For MOZ_NON_OWNING_REF
+#include "mozilla/Attributes.h"     // For MOZ_NON_OWNING_REF
+#include "mozilla/HashFunctions.h"  // For HashNumber, AddToHash
+#include "mozilla/HashTable.h"      // For DefaultHasher, PointerHasher
 #include "mozilla/Maybe.h"
 #include "mozilla/RefPtr.h"
 #include "nsCSSPseudoElements.h"
 
 namespace mozilla {
 
 namespace dom {
 class Element;
@@ -64,11 +66,31 @@ inline void ImplCycleCollectionTraverse(
 }
 
 inline void ImplCycleCollectionUnlink(Maybe<OwningAnimationTarget>& aTarget) {
   if (aTarget) {
     ImplCycleCollectionUnlink(aTarget->mElement);
   }
 }
 
+// A DefaultHasher specialization for OwningAnimationTarget.
+template <>
+struct DefaultHasher<OwningAnimationTarget> {
+  using Key = OwningAnimationTarget;
+  using Lookup = OwningAnimationTarget;
+  using PtrHasher = PointerHasher<dom::Element*>;
+
+  static HashNumber hash(const Lookup& aLookup) {
+    return AddToHash(PtrHasher::hash(aLookup.mElement.get()),
+                     static_cast<uint8_t>(aLookup.mPseudoType));
+  }
+
+  static bool match(const Key& aKey, const Lookup& aLookup) {
+    return PtrHasher::match(aKey.mElement.get(), aLookup.mElement.get()) &&
+           aKey.mPseudoType == aLookup.mPseudoType;
+  }
+
+  static void rekey(Key& aKey, Key&& aNewKey) { aKey = std::move(aNewKey); }
+};
+
 }  // namespace mozilla
 
 #endif  // mozilla_AnimationTarget_h