mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-10 22:00:54 +01:00
Inline DERIVE_EQ and DERIVE_HASH.
This commit is contained in:
parent
2fdc5c8f98
commit
f808ed2438
1 changed files with 34 additions and 26 deletions
|
@ -56,32 +56,28 @@ inline size_t hashCombine(size_t& seed, size_t hash)
|
||||||
using Base::Node; \
|
using Base::Node; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DERIVE_EQ(name, field) \
|
|
||||||
bool operator==(const name& rhs) const \
|
|
||||||
{ \
|
|
||||||
return field == rhs.field; \
|
|
||||||
} \
|
|
||||||
bool operator!=(const name& rhs) const \
|
|
||||||
{ \
|
|
||||||
return !(*this == rhs); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define DERIVE_HASH(name, field) \
|
|
||||||
struct Hash \
|
|
||||||
{ \
|
|
||||||
size_t operator()(const name& value) const \
|
|
||||||
{ \
|
|
||||||
return languageHash(value.field); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Phantom, typename T>
|
template<typename Phantom, typename T>
|
||||||
struct Atom
|
struct Atom
|
||||||
{
|
{
|
||||||
T value;
|
T value;
|
||||||
|
|
||||||
DERIVE_EQ(Atom, value);
|
bool operator==(const Atom& rhs) const
|
||||||
DERIVE_HASH(Atom, value);
|
{
|
||||||
|
return value == rhs.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Atom& rhs) const
|
||||||
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Hash
|
||||||
|
{
|
||||||
|
size_t operator()(const Atom& value) const
|
||||||
|
{
|
||||||
|
return languageHash(value.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Empty base class just for static_asserts.
|
/// Empty base class just for static_asserts.
|
||||||
|
@ -132,12 +128,24 @@ public:
|
||||||
return array[getIndex<T>()];
|
return array[getIndex<T>()];
|
||||||
}
|
}
|
||||||
|
|
||||||
DERIVE_EQ(Node, array);
|
bool operator==(const Node& rhs) const
|
||||||
DERIVE_HASH(Node, array);
|
{
|
||||||
};
|
return array == rhs.array;
|
||||||
|
}
|
||||||
|
|
||||||
#undef DERIVE_EQ
|
bool operator!=(const Node& rhs) const
|
||||||
#undef DERIVE_HASH
|
{
|
||||||
|
return !(*this == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Hash
|
||||||
|
{
|
||||||
|
size_t operator()(const Node& value) const
|
||||||
|
{
|
||||||
|
return languageHash(value.array);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// `Language` is very similar to `Luau::Variant` with enough differences warranting a different type altogether.
|
// `Language` is very similar to `Luau::Variant` with enough differences warranting a different type altogether.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Reference in a new issue