diff --git a/docs/changelog.txt b/docs/changelog.txt index 85ba1c145..668328f22 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -46,6 +46,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `blueprint`: add the ``--cursor`` option to set the starting coordinate for the generated blueprints. a game cursor is no longer necessary if this option is used. - `quickfort`: the Dreamfort blueprint set can now be comfortably built in a 1x1 embark - `tweak` hide-priority: changed so that priorities stay hidden (or visible) when exiting and re-entering the designations menu +- `embark-assistant`: slightly improved performance of surveying and improved code a little ## Lua - ``gui.Painter``: fixed error when calling ``viewport()`` method diff --git a/plugins/embark-assistant/defs.h b/plugins/embark-assistant/defs.h index 9634d7c48..4df27ee3d 100644 --- a/plugins/embark-assistant/defs.h +++ b/plugins/embark-assistant/defs.h @@ -91,9 +91,12 @@ namespace embark_assist { int16_t river_elevation = 100; int8_t adamantine_level; // -1 = none, 0 .. 3 = cavern 1 .. magma sea. Currently not used beyond present/absent. int8_t magma_level; // -1 = none, 0 .. 3 = cavern 3 .. surface/volcano - std::vector metals; - std::vector economics; - std::vector minerals; + // using uint8_t instead of bool as vector gets optimized for a small memory footprint which leads to a significant overhead when iterating over all entries, + // also there seems to be no template specialization for std::fill in MSVS C++11 in regards to std::vector and std::memset does not work as expected (=> not at all that is) + // have a look here https://github.com/DFHack/dfhack/pull/1771#discussion_r579498636 for the related discussion and furter resources + std::vector metals; + std::vector economics; + std::vector minerals; }; typedef std::array, 16> mid_level_tiles; diff --git a/plugins/embark-assistant/survey.cpp b/plugins/embark-assistant/survey.cpp index 9eb2f28b6..f0e14378a 100644 --- a/plugins/embark-assistant/survey.cpp +++ b/plugins/embark-assistant/survey.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "Core.h" #include @@ -909,15 +910,14 @@ void inline copy_incursion_values(embark_assist::defs::mid_level_tile_incursion_ //================================================================================= void reset_mlt_inorganics(embark_assist::defs::mid_level_tiles &mlts) { - const uint16_t size = mlts[0][0].metals.size(); for (uint8_t i = 0; i < 16; i++) { for (uint8_t k = 0; k < 16; k++) { embark_assist::defs::mid_level_tile &mlt = mlts[i][k]; - for (uint16_t l = 0; l < size; l++) { - mlt.metals[l] = false; - mlt.economics[l] = false; - mlt.minerals[l] = false; - } + // std::memset is much faster than std::fill and also faster than direct assignment - also std::fill might be compiled to std::memset but is not guaranteed to happen + // have a look here for why: https://travisdowns.github.io/blog/2020/01/20/zero.html + std::memset(&mlt.metals[0], false, mlt.metals.size() * sizeof(mlt.metals[0])); + std::memset(&mlt.economics[0], false, mlt.economics.size() * sizeof(mlt.economics[0])); + std::memset(&mlt.minerals[0], false, mlt.minerals.size() * sizeof(mlt.minerals[0])); } } }