From a856cf8d4c92b56b651e87df604f4d04a6e977dd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 8 Feb 2022 19:39:47 +0100 Subject: [PATCH] LibWeb: Allow using Origin as a HashMap key --- Userland/Libraries/LibWeb/Origin.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Userland/Libraries/LibWeb/Origin.h b/Userland/Libraries/LibWeb/Origin.h index 3595e791a3..d224b0d734 100644 --- a/Userland/Libraries/LibWeb/Origin.h +++ b/Userland/Libraries/LibWeb/Origin.h @@ -33,6 +33,9 @@ public: && port() == other.port(); } + bool operator==(Origin const& other) const { return is_same(other); } + bool operator!=(Origin const& other) const { return !is_same(other); } + private: String m_protocol; String m_host; @@ -40,3 +43,13 @@ private: }; } + +namespace AK { +template<> +struct Traits : public GenericTraits { + static unsigned hash(Web::Origin const& origin) + { + return pair_int_hash(origin.protocol().hash(), pair_int_hash(int_hash(origin.port()), origin.host().hash())); + } +}; +} // namespace AK