Skip to content

Commit bf22184

Browse files
osjcSmallJoker
authored andcommittedAug 13, 2019
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.
1 parent 72b7a95 commit bf22184

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed
 

Diff for: ‎src/map.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -2214,20 +2214,15 @@ void MMVManip::initialEmerge(v3s16 blockpos_min, v3s16 blockpos_max,
22142214
continue;
22152215

22162216
bool block_data_inexistent = false;
2217-
try
22182217
{
22192218
TimeTaker timer2("emerge load", &emerge_load_time);
22202219

2221-
block = m_map->getBlockNoCreate(p);
2222-
if(block->isDummy())
2220+
block = m_map->getBlockNoCreateNoEx(p);
2221+
if (!block || block->isDummy())
22232222
block_data_inexistent = true;
22242223
else
22252224
block->copyTo(*this);
22262225
}
2227-
catch(InvalidPositionException &e)
2228-
{
2229-
block_data_inexistent = true;
2230-
}
22312226

22322227
if(block_data_inexistent)
22332228
{

Diff for: ‎src/server.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -2287,16 +2287,15 @@ void Server::SendBlocks(float dtime)
22872287
g_settings->getU32("max_simultaneous_block_sends_per_client") / 4 + 1;
22882288

22892289
ScopeProfiler sp(g_profiler, "Server::SendBlocks(): Send to clients");
2290+
Map &map = m_env->getMap();
2291+
22902292
for (const PrioritySortedBlockTransfer &block_to_send : queue) {
22912293
if (total_sending >= max_blocks_to_send)
22922294
break;
22932295

2294-
MapBlock *block = nullptr;
2295-
try {
2296-
block = m_env->getMap().getBlockNoCreate(block_to_send.pos);
2297-
} catch (const InvalidPositionException &e) {
2296+
MapBlock *block = map.getBlockNoCreateNoEx(block_to_send.pos);
2297+
if (!block)
22982298
continue;
2299-
}
23002299

23012300
RemoteClient *client = m_clients.lockedGetClientNoEx(block_to_send.peer_id,
23022301
CS_Active);
@@ -2314,10 +2313,7 @@ void Server::SendBlocks(float dtime)
23142313

23152314
bool Server::SendBlock(session_t peer_id, const v3s16 &blockpos)
23162315
{
2317-
MapBlock *block = nullptr;
2318-
try {
2319-
block = m_env->getMap().getBlockNoCreate(blockpos);
2320-
} catch (InvalidPositionException &e) {};
2316+
MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos);
23212317
if (!block)
23222318
return false;
23232319

0 commit comments

Comments
 (0)
Please sign in to comment.