diff --git a/src/client/fm_far_container.cpp b/src/client/fm_far_container.cpp index 2bf9df40a..fa35fddd9 100644 --- a/src/client/fm_far_container.cpp +++ b/src/client/fm_far_container.cpp @@ -24,8 +24,7 @@ const MapNode &FarContainer::getNodeRefUnsafe(const v3pos_t &pos) const auto &storage = m_client->getEnv().getClientMap().far_blocks_storage[fmesh_step]; - if (const auto &it = storage.find(bpos_aligned); it != storage.end()) { - const auto &block = it->second; + if (const auto &block = storage.at_or(bpos_aligned)) { v3pos_t relpos = pos - bpos_aligned * MAP_BLOCKSIZE; const auto &relpos_shift = fmesh_step; // + 1; diff --git a/src/threading/concurrent_unordered_map.h b/src/threading/concurrent_unordered_map.h index a21b8316b..131198ac0 100644 --- a/src/threading/concurrent_unordered_map.h +++ b/src/threading/concurrent_unordered_map.h @@ -71,6 +71,15 @@ class concurrent_unordered_map_ : public std::unordered_map(args)...); } + const mapped_type &at_or(const key_type &k, const mapped_type ¬hing = {}) const + { + auto lock = LOCKER::lock_shared_rec(); + if (const auto it = full_type::find(k); it != full_type::end()) { + return it->second; + } + return nothing; + } + template decltype(auto) assign(Args &&...args) { diff --git a/src/threading/concurrent_unordered_set.h b/src/threading/concurrent_unordered_set.h index 2e94348e5..040f108ca 100644 --- a/src/threading/concurrent_unordered_set.h +++ b/src/threading/concurrent_unordered_set.h @@ -36,7 +36,7 @@ class concurrent_unordered_set_ : public std::unordered_set - Value &at_or(Args &&...args, const Value ¬hing = {}) + const Value &at_or(Args &&...args, const Value ¬hing = {}) const { auto lock = LOCKER::lock_shared_rec(); if (const auto it = full_type::find(std::forward(args)...);