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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Brian Birtles 2019-05-20 05:22:07 +00:00
parent 25c05a66db
commit c7c4f6d875

View File

@ -7,7 +7,9 @@
#ifndef mozilla_AnimationTarget_h #ifndef mozilla_AnimationTarget_h
#define 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/Maybe.h"
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "nsCSSPseudoElements.h" #include "nsCSSPseudoElements.h"
@ -69,6 +71,26 @@ inline void ImplCycleCollectionUnlink(Maybe<OwningAnimationTarget>& aTarget) {
} }
} }
// 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 } // namespace mozilla
#endif // mozilla_AnimationTarget_h #endif // mozilla_AnimationTarget_h