From ee1a527191db646850ee919b8fe3a6f8cb6cd693 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 10 Nov 2022 21:27:08 +0100 Subject: get rid of std::string --- editor/tile-editor.cpp | 17 ++++++----------- editor/tile-editor.hpp | 5 ++--- 2 files changed, 8 insertions(+), 14 deletions(-) (limited to 'editor') diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp index 2a0e9abc..f396d64a 100644 --- a/editor/tile-editor.cpp +++ b/editor/tile-editor.cpp @@ -6,7 +6,6 @@ #include "random.hpp" #include "serialize/json-helper.hpp" #include "serialize/tile-atlas.hpp" -#include #include namespace floormat { @@ -27,26 +26,22 @@ void tile_editor::load_atlases() if (auto x = name.findLast('.'); x) name = name.prefix(x.data()); auto& [_, vec] = _permutation; - vec.reserve((std::size_t)atlas->num_tiles()); - _atlases[name] = std::move(atlas); + vec.reserve(atlas->num_tiles()); + _atlases[name] = atlas; } } std::shared_ptr tile_editor::maybe_atlas(StringView str) { - auto it = std::find_if(_atlases.begin(), _atlases.end(), [&](const auto& tuple) -> bool { - const auto& [x, _] = tuple; - return StringView{x} == str; - }); - if (it == _atlases.end()) - return nullptr; - else + if (auto it = _atlases.find(str); it != _atlases.end()) return it->second; + else + return nullptr; } std::shared_ptr tile_editor::atlas(StringView str) { - if (auto ptr = maybe_atlas(str); ptr) + if (auto ptr = maybe_atlas(str)) return ptr; else fm_abort("no such atlas: %s", str.cbegin()); diff --git a/editor/tile-editor.hpp b/editor/tile-editor.hpp index 53b12e55..9f4bb2db 100644 --- a/editor/tile-editor.hpp +++ b/editor/tile-editor.hpp @@ -4,10 +4,9 @@ #include "src/tile-image.hpp" #include "global-coords.hpp" #include -#include #include #include -#include +#include namespace floormat { @@ -25,7 +24,7 @@ private: std::vector variant; }; - std::string _name; + String _name; std::map> _atlases; tile_image_proto _selected_tile; tuple _permutation; -- cgit v1.2.3