]> git.lizzy.rs Git - minetest.git/blobdiff - src/minimap.cpp
Precalculate mapblock relative size. This permit to remove many s16 calculs on runtime
[minetest.git] / src / minimap.cpp
index d37a083efd18307bd1750c3a2ad087b9cc89a6c3..950202c6a4f8895bce0cc8ed16b6779d0ac31126 100644 (file)
@@ -102,7 +102,13 @@ void MinimapUpdateThread::doUpdate()
 
        while (popBlockUpdate(&update)) {
                if (update.data) {
-                       m_blocks_cache[update.pos] = update.data;
+                       // Swap two values in the map using single lookup
+                       std::pair<std::map<v3s16, MinimapMapblock*>::iterator, bool>
+                           result = m_blocks_cache.insert(std::make_pair(update.pos, update.data));
+                       if (result.second == false) {
+                               delete result.first->second;
+                               result.first->second = update.data;
+                       }
                } else {
                        std::map<v3s16, MinimapMapblock *>::iterator it;
                        it = m_blocks_cache.find(update.pos);