Skip to content

Commit 14a1a71

Browse files
committedJul 18, 2017
Very little performance fix on correctBlockNodeIds
+ C++11 codestyle
1 parent 5117ce4 commit 14a1a71

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed
 

‎src/mapblock.cpp

+13-18
Original file line numberDiff line numberDiff line change
@@ -492,19 +492,17 @@ static void correctBlockNodeIds(const NameIdMapping *nimap, MapNode *nodes,
492492
// the information to convert those to names.
493493
// nodedef contains information to convert our names to globally
494494
// correct ids.
495-
std::set<content_t> unnamed_contents;
496-
std::set<std::string> unallocatable_contents;
495+
std::unordered_set<content_t> unnamed_contents;
496+
std::unordered_set<std::string> unallocatable_contents;
497497
for (u32 i = 0; i < MapBlock::nodecount; i++) {
498498
content_t local_id = nodes[i].getContent();
499499
std::string name;
500-
bool found = nimap->getName(local_id, name);
501-
if(!found){
500+
if (!nimap->getName(local_id, name)) {
502501
unnamed_contents.insert(local_id);
503502
continue;
504503
}
505504
content_t global_id;
506-
found = nodedef->getId(name, global_id);
507-
if(!found){
505+
if (!nodedef->getId(name, global_id)) {
508506
global_id = gamedef->allocateUnknownNodeId(name);
509507
if(global_id == CONTENT_IGNORE){
510508
unallocatable_contents.insert(name);
@@ -513,19 +511,16 @@ static void correctBlockNodeIds(const NameIdMapping *nimap, MapNode *nodes,
513511
}
514512
nodes[i].setContent(global_id);
515513
}
516-
for(std::set<content_t>::const_iterator
517-
i = unnamed_contents.begin();
518-
i != unnamed_contents.end(); ++i){
519-
errorstream<<"correctBlockNodeIds(): IGNORING ERROR: "
520-
<<"Block contains id "<<(*i)
521-
<<" with no name mapping"<<std::endl;
514+
515+
for (const content_t c: unnamed_contents) {
516+
errorstream << "correctBlockNodeIds(): IGNORING ERROR: "
517+
<< "Block contains id " << c
518+
<< " with no name mapping" << std::endl;
522519
}
523-
for(std::set<std::string>::const_iterator
524-
i = unallocatable_contents.begin();
525-
i != unallocatable_contents.end(); ++i){
526-
errorstream<<"correctBlockNodeIds(): IGNORING ERROR: "
527-
<<"Could not allocate global id for node name \""
528-
<<(*i)<<"\""<<std::endl;
520+
for (const std::string &node_name: unallocatable_contents) {
521+
errorstream << "correctBlockNodeIds(): IGNORING ERROR: "
522+
<< "Could not allocate global id for node name \""
523+
<< node_name << "\"" << std::endl;
529524
}
530525
}
531526

0 commit comments

Comments
 (0)
Please sign in to comment.