diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-11 12:50:15 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-11-11 12:50:15 +0100 |
| commit | e442f629e0bb5615a7c89339fd6c1420944b293d (patch) | |
| tree | 7509aeef44f0e54977991956b6e8691c46528eed | |
| parent | 511faeef4f5b53fd0247dc0db1b8ccc1437af047 (diff) | |
use emplacer instead of unordered_map::find
| -rw-r--r-- | serialize/world-writer.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/serialize/world-writer.cpp b/serialize/world-writer.cpp index 7e89c508..3a98d5b5 100644 --- a/serialize/world-writer.cpp +++ b/serialize/world-writer.cpp @@ -6,6 +6,7 @@ #include "src/global-coords.hpp" #include "src/chunk.hpp" #include "src/world.hpp" +#include "src/emplacer.hpp" #include <vector> #include <algorithm> #include <cstring> @@ -67,10 +68,8 @@ atlasid writer_state::intern_atlas(const tile_image_proto& img) { const void* const ptr = img.atlas.get(); fm_debug_assert(ptr != nullptr); - if (auto it = tile_images.find(ptr); it != tile_images.end()) - return it->second.index; - else - return (tile_images[ptr] = { &*img.atlas, (atlasid)tile_images.size() }).index; + emplacer e{[&] -> interned_atlas { return { &*img.atlas, (atlasid)tile_images.size() }; }}; + return tile_images.try_emplace(ptr, e).first->second.index; } atlasid writer_state::maybe_intern_atlas(const tile_image_proto& img) |
