diff options
author | sapier <Sapier at GMX dot net> | 2014-06-08 17:25:52 +0200 |
---|---|---|
committer | sapier <Sapier at GMX dot net> | 2014-06-23 00:13:41 +0200 |
commit | 5d06bdf8ac3b38b1ffb400fd771a245589d92ad1 (patch) | |
tree | ecedbb633ccf12a65f2b38363c29901d13272588 /src/mapblock.cpp | |
parent | 2625323f25ebb4e9ab1079ff60a77b40f58c5bf9 (diff) | |
download | minetest-5d06bdf8ac3b38b1ffb400fd771a245589d92ad1.tar.gz minetest-5d06bdf8ac3b38b1ffb400fd771a245589d92ad1.tar.bz2 minetest-5d06bdf8ac3b38b1ffb400fd771a245589d92ad1.zip |
Speedup getBlockNodeIdMapping by up to factor 4 by using a fixed size mapping array
Diffstat (limited to 'src/mapblock.cpp')
-rw-r--r-- | src/mapblock.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 95e54fb33..8e8961e10 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -452,10 +452,16 @@ s16 MapBlock::getGroundLevel(v2s16 p2d) */ // List relevant id-name pairs for ids in the block using nodedef // Renumbers the content IDs (starting at 0 and incrementing +// use static memory requires about 65535 * sizeof(int) ram in order to be +// sure we can handle all content ids. But it's absolutely worth it as it's +// a speedup of 4 for one of the major time consuming functions on storing +// mapblocks. +static content_t getBlockNodeIdMapping_mapping[USHRT_MAX]; static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes, INodeDefManager *nodedef) { - std::map<content_t, content_t> mapping; + memset(getBlockNodeIdMapping_mapping, 0xFF, USHRT_MAX * sizeof(content_t)); + std::set<content_t> unknown_contents; content_t id_counter = 0; for(u32 i=0; i<MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++) @@ -464,16 +470,14 @@ static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes, content_t id = CONTENT_IGNORE; // Try to find an existing mapping - std::map<content_t, content_t>::iterator j = mapping.find(global_id); - if(j != mapping.end()) - { - id = j->second; + if (getBlockNodeIdMapping_mapping[global_id] != 0xFFFF) { + id = getBlockNodeIdMapping_mapping[global_id]; } else { // We have to assign a new mapping id = id_counter++; - mapping.insert(std::make_pair(global_id, id)); + getBlockNodeIdMapping_mapping[global_id] = id; const ContentFeatures &f = nodedef->get(global_id); const std::string &name = f.name; |