1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsURIHashKey_h__
6 #define nsURIHashKey_h__
10 #include "PLDHashTable.h"
11 #include "mozilla/Unused.h"
13 #include "nsHashKeys.h"
17 * Hashtable key class to use with nsTHashtable/nsBaseHashtable
19 class nsURIHashKey
: public PLDHashEntryHdr
{
21 typedef nsIURI
* KeyType
;
22 typedef const nsIURI
* KeyTypePointer
;
24 nsURIHashKey() { MOZ_COUNT_CTOR(nsURIHashKey
); }
25 explicit nsURIHashKey(const nsIURI
* aKey
) : mKey(const_cast<nsIURI
*>(aKey
)) {
26 MOZ_COUNT_CTOR(nsURIHashKey
);
28 nsURIHashKey(nsURIHashKey
&& toMove
)
29 : PLDHashEntryHdr(std::move(toMove
)), mKey(std::move(toMove
.mKey
)) {
30 MOZ_COUNT_CTOR(nsURIHashKey
);
32 MOZ_COUNTED_DTOR(nsURIHashKey
)
34 nsURIHashKey
& operator=(const nsURIHashKey
& aOther
) {
39 nsIURI
* GetKey() const { return mKey
; }
41 bool KeyEquals(const nsIURI
* aKey
) const {
46 if (NS_SUCCEEDED(mKey
->Equals(const_cast<nsIURI
*>(aKey
), &eq
))) {
52 static const nsIURI
* KeyToPointer(nsIURI
* aKey
) { return aKey
; }
53 static PLDHashNumber
HashKey(const nsIURI
* aKey
) {
55 // If the key is null, return hash for empty string.
56 return mozilla::HashString(""_ns
);
59 // If GetSpec() fails, ignoring the failure and proceeding with an
60 // empty |spec| seems like the best thing to do.
61 mozilla::Unused
<< const_cast<nsIURI
*>(aKey
)->GetSpec(spec
);
62 return mozilla::HashString(spec
);
65 enum { ALLOW_MEMMOVE
= true };
68 nsCOMPtr
<nsIURI
> mKey
;
71 #endif // nsURIHashKey_h__