Files
sousa-gecko/caps/OriginAttributesHashKey.h
Lars Eggert 23c61cf3f4 Bug 2026910 - Add OriginAttributes::Hash() and use it for hashing r=valentin,kershaw,necko-reviewers,cookie-reviewers,tschuster
Add a Hash() method to OriginAttributes that combines all fields using
AddToHash/HashString, and use it in CookieKey::HashKey(),
OriginAttributesHashKey::HashKey(), and BuildOriginFrameHashKey(),
replacing CreateSuffix()-based hashing with direct field hashing.

Differential Revision: https://phabricator.services.mozilla.com/D290377
2026-03-30 11:30:25 +00:00

49 lines
1.3 KiB
C++

/* 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_OriginAttributesHashKey_h
#define mozilla_OriginAttributesHashKey_h
#include "OriginAttributes.h"
#include "PLDHashTable.h"
namespace mozilla {
class OriginAttributesHashKey : public PLDHashEntryHdr {
public:
using KeyType = OriginAttributes;
using KeyTypeRef = const KeyType&;
using KeyTypePointer = const KeyType*;
explicit OriginAttributesHashKey(KeyTypePointer aKey) {
mOriginAttributes = *aKey;
MOZ_COUNT_CTOR(OriginAttributesHashKey);
}
OriginAttributesHashKey(OriginAttributesHashKey&& aKey) noexcept {
mOriginAttributes = std::move(aKey.mOriginAttributes);
MOZ_COUNT_CTOR(OriginAttributesHashKey);
}
MOZ_COUNTED_DTOR(OriginAttributesHashKey)
KeyTypeRef GetKey() const { return mOriginAttributes; }
bool KeyEquals(KeyTypePointer aKey) const {
return mOriginAttributes == *aKey;
}
static KeyTypePointer KeyToPointer(KeyTypeRef aKey) { return &aKey; }
static PLDHashNumber HashKey(KeyTypePointer aKey) { return aKey->Hash(); }
enum { ALLOW_MEMMOVE = true };
protected:
OriginAttributes mOriginAttributes;
};
} // namespace mozilla
#endif