1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Definitions for nsAtom-related hash keys */
9 #ifndef nsAtomHashKeys_h
10 #define nsAtomHashKeys_h
13 #include "nsHashKeys.h"
15 // TODO(emilio): Consider removing this and specializing AddToHash instead
16 // once bug 1849386 is fixed.
18 // Hash keys suitable for use in nsTHashTable.
19 struct nsAtomHashKey
: public nsRefPtrHashKey
<nsAtom
> {
20 using nsRefPtrHashKey::nsRefPtrHashKey
;
21 static PLDHashNumber
HashKey(KeyTypePointer aKey
) {
22 return MOZ_LIKELY(aKey
) ? aKey
->hash() : 0;
26 struct nsWeakAtomHashKey
: public nsPtrHashKey
<nsAtom
> {
27 using nsPtrHashKey::nsPtrHashKey
;
28 static PLDHashNumber
HashKey(KeyTypePointer aKey
) {
29 return nsAtomHashKey::HashKey(aKey
);
33 // Hash keys suitable for use in mozilla::HashMap.
39 explicit AtomHashKey(nsAtom
* aAtom
) : mKey(aAtom
) {}
41 using Lookup
= nsAtom
*;
43 static HashNumber
hash(const Lookup
& aKey
) { return aKey
->hash(); }
44 static bool match(const AtomHashKey
& aFirst
, const Lookup
& aSecond
) {
45 return aFirst
.mKey
== aSecond
;
49 } // namespace mozilla
51 #endif // nsAtomHashKeys_h