Skip to content

Commit

Permalink
caching results
Browse files Browse the repository at this point in the history
  • Loading branch information
holysnipz committed Feb 17, 2024
1 parent 5a147f7 commit 69e51e7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ChaosMod/Util/Weapon.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#pragma once

#include <unordered_map>

using Hash = unsigned long;

namespace Util
{
inline bool IsWeaponShotgun(Hash weaponHash)
{
return GET_WEAPONTYPE_GROUP(weaponHash) == "GROUP_SHOTGUN"_hash;
static std::unordered_map<Hash, bool> cachedResults;
static const Hash shotgunGroup = "GROUP_SHOTGUN"_hash;

if (const auto result = cachedResults.find(weaponHash); result != cachedResults.end())
{
return result->second;
}

return cachedResults.emplace(weaponHash, (GET_WEAPONTYPE_GROUP(weaponHash) == shotgunGroup)).first->second;
}
}

0 comments on commit 69e51e7

Please sign in to comment.