1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Improve std::hash<SMaterial> implementation

This commit is contained in:
sfan5 2025-03-26 18:28:25 +01:00
parent d7edf0b229
commit 89e3bc8d56

View file

@ -483,9 +483,15 @@ struct std::hash<irr::video::SMaterial>
/// @brief std::hash specialization for video::SMaterial /// @brief std::hash specialization for video::SMaterial
std::size_t operator()(const irr::video::SMaterial &m) const noexcept std::size_t operator()(const irr::video::SMaterial &m) const noexcept
{ {
// basic implementation that hashes the two things most likely to differ std::size_t ret = 0;
auto h1 = std::hash<irr::video::ITexture*>{}(m.getTexture(0)); for (auto h : { // the three members most likely to differ
auto h2 = std::hash<int>{}(m.MaterialType); std::hash<irr::video::ITexture*>{}(m.getTexture(0)),
return (h1 << 1) ^ h2; std::hash<int>{}(m.MaterialType),
std::hash<irr::u32>{}(m.ColorParam.color)
}) {
ret += h;
ret ^= (ret << 6) + (ret >> 2); // distribute bits
}
return ret;
} }
}; };