diff options
Diffstat (limited to 'source/blender/blenlib/BLI_hash.hh')
-rw-r--r-- | source/blender/blenlib/BLI_hash.hh | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/source/blender/blenlib/BLI_hash.hh b/source/blender/blenlib/BLI_hash.hh index b14a4ca933c..2e3212cc83b 100644 --- a/source/blender/blenlib/BLI_hash.hh +++ b/source/blender/blenlib/BLI_hash.hh @@ -14,8 +14,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __BLI_HASH_HH__ -#define __BLI_HASH_HH__ +#pragma once /** \file * \ingroup bli @@ -111,7 +110,7 @@ template<typename T> struct DefaultHash<const T> { template<> struct DefaultHash<TYPE> { \ uint64_t operator()(TYPE value) const \ { \ - return (uint64_t)value; \ + return static_cast<uint64_t>(value); \ } \ } @@ -136,14 +135,14 @@ TRIVIAL_DEFAULT_INT_HASH(uint64_t); template<> struct DefaultHash<float> { uint64_t operator()(float value) const { - return *(uint32_t *)&value; + return *reinterpret_cast<uint32_t *>(&value); } }; template<> struct DefaultHash<bool> { uint64_t operator()(bool value) const { - return (uint64_t)(value != false) * 1298191; + return static_cast<uint64_t>((value != false) * 1298191); } }; @@ -181,14 +180,21 @@ template<> struct DefaultHash<StringRefNull> { } }; +template<> struct DefaultHash<std::string_view> { + uint64_t operator()(StringRef value) const + { + return hash_string(value); + } +}; + /** * While we cannot guarantee that the lower 4 bits of a pointer are zero, it is often the case. */ template<typename T> struct DefaultHash<T *> { uint64_t operator()(const T *value) const { - uintptr_t ptr = (uintptr_t)value; - uint64_t hash = (uint64_t)(ptr >> 4); + uintptr_t ptr = reinterpret_cast<uintptr_t>(value); + uint64_t hash = static_cast<uint64_t>(ptr >> 4); return hash; } }; @@ -210,5 +216,3 @@ template<typename T1, typename T2> struct DefaultHash<std::pair<T1, T2>> { }; } // namespace blender - -#endif /* __BLI_HASH_HH__ */ |