Fix unnecessary exception use in 3 more methods (#8791)

* Fix unnecessary exception use in Server::SendBlocks

The code in this method calls getBlockNoCreate and then
messes around with try...catch to skip blocks which are not
in the memory. Additionally, it repeatedly calls
m_env.getMap() inside this loop. Speed the code up by
extracting the m_env.getMap() out of the loop and getting
rid of the try...catch.

* Fix unnecessary exception use in Server::SendBlock

Another unnecessary try...catch is slowing down
Server::SendBlock. Remove that to speed it up and get a nice
side effect of simplifying the code in question.

* Fix unnecessary exception use in MMVManip::initialEmerge

Remove another unneeded exception usage from
MMVManip::initialEmerge to speed that code up and simplify
it but be careful to not remove the braces as there is a
TimeTaker in use there.
This commit is contained in:
Jozef Behran 2019-08-13 20:02:50 +02:00 committed by SmallJoker
parent 72b7a957af
commit bf22184d6e
2 changed files with 7 additions and 16 deletions

@ -2214,20 +2214,15 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
continue; continue;
bool block_data_inexistent = false; bool block_data_inexistent = false;
try
{ {
TimeTaker timer2("emerge load", &emerge_load_time); TimeTaker timer2("emerge load", &emerge_load_time);
block = m_map->getBlockNoCreate(p); block = m_map->getBlockNoCreateNoEx(p);
if(block->isDummy()) if (!block || block->isDummy())
block_data_inexistent = true; block_data_inexistent = true;
else else
block->copyTo(*this); block->copyTo(*this);
} }
catch(InvalidPositionException &e)
{
block_data_inexistent = true;
}
if(block_data_inexistent) if(block_data_inexistent)
{ {

@ -2287,16 +2287,15 @@ void Server::SendBlocks(float dtime)
g_settings->getU32("max_simultaneous_block_sends_per_client") / 4 + 1; g_settings->getU32("max_simultaneous_block_sends_per_client") / 4 + 1;
ScopeProfiler sp(g_profiler, "Server::SendBlocks(): Send to clients"); ScopeProfiler sp(g_profiler, "Server::SendBlocks(): Send to clients");
Map &map = m_env->getMap();
for (const PrioritySortedBlockTransfer &block_to_send : queue) { for (const PrioritySortedBlockTransfer &block_to_send : queue) {
if (total_sending >= max_blocks_to_send) if (total_sending >= max_blocks_to_send)
break; break;
MapBlock *block = nullptr; MapBlock *block = map.getBlockNoCreateNoEx(block_to_send.pos);
try { if (!block)
block = m_env->getMap().getBlockNoCreate(block_to_send.pos);
} catch (const InvalidPositionException &e) {
continue; continue;
}
RemoteClient *client = m_clients.lockedGetClientNoEx(block_to_send.peer_id, RemoteClient *client = m_clients.lockedGetClientNoEx(block_to_send.peer_id,
CS_Active); CS_Active);
@ -2314,10 +2313,7 @@ void Server::SendBlocks(float dtime)
bool Server::SendBlock(session_t peer_id, const v3s16 &blockpos) bool Server::SendBlock(session_t peer_id, const v3s16 &blockpos)
{ {
MapBlock *block = nullptr; MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos);
try {
block = m_env->getMap().getBlockNoCreate(blockpos);
} catch (InvalidPositionException &e) {};
if (!block) if (!block)
return false; return false;