From 821ef6e0965db31fe110e9659ab7a5dd4b538f15 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 8 Dec 2022 12:41:49 +0100 Subject: loader: use StringView as keys --- loader/atlas.cpp | 12 ++++++------ loader/impl.hpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'loader') diff --git a/loader/atlas.cpp b/loader/atlas.cpp index d39a0c40..89b988e9 100644 --- a/loader/atlas.cpp +++ b/loader/atlas.cpp @@ -16,11 +16,12 @@ namespace floormat::loader_detail { std::shared_ptr loader_impl::tile_atlas(StringView name, Vector2ub size, Optional pass) noexcept(false) { - fm_soft_assert(check_atlas_name(name)); + if (auto it = tile_atlas_map.find(name); it != tile_atlas_map.end()) + return it->second; - const emplacer e{[&] { return std::make_shared(name, texture(IMAGE_PATH, name), size, pass); }}; - auto atlas = tile_atlas_map.try_emplace(name, e).first->second; - fm_soft_assert(!pass || pass == atlas->pass_mode()); + fm_soft_assert(check_atlas_name(name)); + auto atlas = std::make_shared(name, texture(IMAGE_PATH, name), size, pass); + tile_atlas_map[atlas->name()] = atlas; return atlas; } @@ -42,12 +43,11 @@ ArrayView loader_impl::anim_atlas_list() std::shared_ptr loader_impl::anim_atlas(StringView name, StringView dir) noexcept(false) { - fm_soft_assert(check_atlas_name(name)); - if (auto it = anim_atlas_map.find(name); it != anim_atlas_map.end()) return it->second; else { + fm_soft_assert(check_atlas_name(name)); const auto path = Path::join(dir, Path::splitExtension(name).first()); auto anim_info = deserialize_anim(path + ".json"); diff --git a/loader/impl.hpp b/loader/impl.hpp index 673460aa..e1d6d649 100644 --- a/loader/impl.hpp +++ b/loader/impl.hpp @@ -21,8 +21,8 @@ struct loader_impl final : loader_ Containers::Pointer image_importer; Containers::Pointer tga_importer; - std::unordered_map> tile_atlas_map; - std::unordered_map> anim_atlas_map; + std::unordered_map> tile_atlas_map; + std::unordered_map> anim_atlas_map; std::vector anim_atlases; std::vector sceneries_array; -- cgit v1.2.3