From 89e3bc8d562c23e1e527826b27c5f1e2bf094077 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 26 Mar 2025 18:28:25 +0100 Subject: [PATCH] Improve std::hash implementation --- irr/include/SMaterial.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/irr/include/SMaterial.h b/irr/include/SMaterial.h index d48328a31..d5b9341f4 100644 --- a/irr/include/SMaterial.h +++ b/irr/include/SMaterial.h @@ -483,9 +483,15 @@ struct std::hash /// @brief std::hash specialization for video::SMaterial std::size_t operator()(const irr::video::SMaterial &m) const noexcept { - // basic implementation that hashes the two things most likely to differ - auto h1 = std::hash{}(m.getTexture(0)); - auto h2 = std::hash{}(m.MaterialType); - return (h1 << 1) ^ h2; + std::size_t ret = 0; + for (auto h : { // the three members most likely to differ + std::hash{}(m.getTexture(0)), + std::hash{}(m.MaterialType), + std::hash{}(m.ColorParam.color) + }) { + ret += h; + ret ^= (ret << 6) + (ret >> 2); // distribute bits + } + return ret; } };