From a0e8e4265ad3ad42d6b616538477421b881f7f59 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 11 Mar 2015 13:59:25 +0000 Subject: [PATCH] coords/units hashing refactoring --- src/coord.hh | 15 +++++---------- src/units.hh | 9 +++------ src/value.hh | 2 -- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/coord.hh b/src/coord.hh index aae08ba9..252496d1 100644 --- a/src/coord.hh +++ b/src/coord.hh @@ -84,6 +84,11 @@ struct LineAndColumn { return line != other.line or column != other.column; } + + friend size_t hash_value(const EffectiveType& val) + { + return hash_values(val.line, val.column); + } }; struct ByteCoord : LineAndColumn @@ -93,11 +98,6 @@ struct ByteCoord : LineAndColumn : LineAndColumn(line, column) {} }; -inline size_t hash_value(const ByteCoord& val) -{ - return hash_values(val.line, val.column); -} - struct CharCoord : LineAndColumn { [[gnu::always_inline]] @@ -105,11 +105,6 @@ struct CharCoord : LineAndColumn : LineAndColumn(line, column) {} }; -inline size_t hash_value(const CharCoord& val) -{ - return hash_values(val.line, val.column); -} - struct ByteCoordAndTarget : ByteCoord { [[gnu::always_inline]] diff --git a/src/units.hh b/src/units.hh index 5091c324..945f7265 100644 --- a/src/units.hh +++ b/src/units.hh @@ -111,6 +111,9 @@ public: explicit constexpr operator ValueType() const { return m_value; } [[gnu::always_inline]] explicit constexpr operator bool() const { return m_value; } + + friend size_t hash_value(RealType val) { return hash_value(val.m_value); } + private: ValueType m_value; }; @@ -121,8 +124,6 @@ struct LineCount : public StronglyTypedNumber constexpr LineCount(int value = 0) : StronglyTypedNumber(value) {} }; -inline size_t hash_value(LineCount val) { return hash_value((int)val); } - [[gnu::always_inline]] inline constexpr LineCount operator"" _line(unsigned long long int value) { @@ -135,8 +136,6 @@ struct ByteCount : public StronglyTypedNumber constexpr ByteCount(int value = 0) : StronglyTypedNumber(value) {} }; -inline size_t hash_value(ByteCount val) { return hash_value((int)val); } - [[gnu::always_inline]] inline constexpr ByteCount operator"" _byte(unsigned long long int value) { @@ -155,8 +154,6 @@ inline constexpr CharCount operator"" _char(unsigned long long int value) return CharCount(value); } -inline size_t hash_value(CharCount val) { return hash_value((int)val); } - } #endif // units_hh_INCLUDED diff --git a/src/value.hh b/src/value.hh index 51318c2d..1a287b0b 100644 --- a/src/value.hh +++ b/src/value.hh @@ -76,8 +76,6 @@ struct ValueId : public StronglyTypedNumber } }; -inline size_t hash_value(ValueId val) { return hash_value((int)val); } - using ValueMap = UnorderedMap; }