gltfpack: Switch primitive cache to std::unordered_map

Neither std::map nor std::unordered_map are particularly good
containers, but since we're now using unordered_map for deduplication
filtering we might as well use it for the primitive cache. This requires
a custom hash function for pair<uint64, uint64>, but our hash halves are
sufficiently decorellated that a xor suffices.
This commit is contained in:
Arseny Kapoulkine
2024-10-16 08:42:09 -07:00
parent 3d95a623bc
commit ed47a6d848
+14 -2
View File
@@ -2,7 +2,7 @@
#include "gltfpack.h"
#include <algorithm>
#include <map>
#include <unordered_map>
#include <locale.h>
#include <stdint.h>
@@ -329,6 +329,18 @@ static bool isExtensionSupported(const ExtensionInfo* extensions, size_t count,
return false;
}
namespace std
{
template <>
struct hash<std::pair<uint64_t, uint64_t> >
{
size_t operator()(const std::pair<uint64_t, uint64_t>& x) const
{
return std::hash<uint64_t>()(x.first ^ x.second);
}
};
} // namespace std
static void process(cgltf_data* data, const char* input_path, const char* output_path, const char* report_path, std::vector<Mesh>& meshes, std::vector<Animation>& animations, const Settings& settings, std::string& json, std::string& bin, std::string& fallback, size_t& fallback_size)
{
if (settings.verbose)
@@ -565,7 +577,7 @@ static void process(cgltf_data* data, const char* input_path, const char* output
ext_texture_transform = ext_texture_transform || mi.uses_texture_transform;
}
std::map<std::pair<uint64_t, uint64_t>, std::pair<size_t, size_t> > primitive_cache;
std::unordered_map<std::pair<uint64_t, uint64_t>, std::pair<size_t, size_t> > primitive_cache;
for (size_t i = 0; i < meshes.size(); ++i)
{