From 6d200654e414a5b6035720718f11c52847fd1360 Mon Sep 17 00:00:00 2001 From: korenkonder Date: Wed, 30 Aug 2023 21:32:37 +0300 Subject: [PATCH] Optimized Glitter Editor hash search --- src/CRE/data.cpp | 12 ++++----- src/CRE/data.hpp | 4 +-- src/ReDIVA/classes/glitter_editor.cpp | 35 ++++++++------------------- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/src/CRE/data.cpp b/src/CRE/data.cpp index d8395574..a810f227 100644 --- a/src/CRE/data.cpp +++ b/src/CRE/data.cpp @@ -1038,18 +1038,18 @@ static void data_load_glitter_list(data_struct* ds, const char* path) { case DATA_X: case DATA_XHD: ds->glitter_list_murmurhash.reserve(count); - for (size_t i = 0; i < count; i++) { - uint32_t hash = hash_string_murmurhash(ds->glitter_list_names[i]); - ds->glitter_list_murmurhash.push_back(hash); + for (std::string& i : ds->glitter_list_names) { + uint32_t hash = hash_string_murmurhash(i); + ds->glitter_list_murmurhash.push_back(hash, i.c_str()); } break; case DATA_AFT: case DATA_FT: case DATA_M39: ds->glitter_list_fnv1a64m.reserve(count); - for (size_t i = 0; i < count; i++) { - uint64_t hash = hash_string_fnv1a64m(ds->glitter_list_names[i]); - ds->glitter_list_fnv1a64m.push_back(hash); + for (std::string& i : ds->glitter_list_names) { + uint64_t hash = hash_string_fnv1a64m(i); + ds->glitter_list_fnv1a64m.push_back(hash, i.c_str()); } break; } diff --git a/src/CRE/data.hpp b/src/CRE/data.hpp index 71e744fd..5b631d22 100644 --- a/src/CRE/data.hpp +++ b/src/CRE/data.hpp @@ -94,8 +94,8 @@ struct data_struct { std::vector data_paths; #if defined(CRE_DEV) std::vector glitter_list_names; - std::vector glitter_list_fnv1a64m; - std::vector glitter_list_murmurhash; + prj::vector_pair glitter_list_fnv1a64m; + prj::vector_pair glitter_list_murmurhash; #endif #if defined(CRE_DEV) data_f2 data_f2; diff --git a/src/ReDIVA/classes/glitter_editor.cpp b/src/ReDIVA/classes/glitter_editor.cpp index b52ee46b..46ffd9e8 100644 --- a/src/ReDIVA/classes/glitter_editor.cpp +++ b/src/ReDIVA/classes/glitter_editor.cpp @@ -931,7 +931,7 @@ void glitter_editor_ctrl(class_data* data) { case DATA_VRFL: case DATA_X: case DATA_XHD: { - std::vector& hashes = ds->glitter_list_murmurhash; + auto& hashes = ds->glitter_list_murmurhash; for (Glitter::Effect*& i : eg->effects) { if (!i) continue; @@ -941,19 +941,11 @@ void glitter_editor_ctrl(class_data* data) { if (e->data.name_hash == hash_murmurhash_empty) continue; - std::vector::iterator hash = hashes.end(); - for (std::vector::iterator j = hashes.begin(); j != hashes.end(); j++) - if (e->data.name_hash == *j) { - hash = j; - break; - } - - if (hash == hashes.end()) { + auto elem = hashes.find(e->data.name_hash); + if (elem != hashes.end()) + e->name.assign(elem->second); + else load_success = false; - continue; - } - - e->name.assign(ds->glitter_list_names[hash - hashes.begin()]); } switch (ds->type) { @@ -970,7 +962,7 @@ void glitter_editor_ctrl(class_data* data) { case DATA_AFT: case DATA_FT: case DATA_M39: { - std::vector& hashes = ds->glitter_list_fnv1a64m; + auto& hashes = ds->glitter_list_fnv1a64m; for (Glitter::Effect* i : eg->effects) { if (!i) continue; @@ -980,19 +972,12 @@ void glitter_editor_ctrl(class_data* data) { if (e->data.name_hash == hash_fnv1a64m_empty) continue; - std::vector::iterator hash = hashes.end(); - for (std::vector::iterator j = hashes.begin(); j != hashes.end(); j++) - if (e->data.name_hash == *j) { - hash = j; - break; - } - - if (hash == hashes.end()) { + auto elem = hashes.find(e->data.name_hash); + if (elem != hashes.end()) + e->name.assign(elem->second); + else load_success = false; - continue; - } - e->name.assign(ds->glitter_list_names[hash - hashes.begin()]); } } break; }