summaryrefslogtreecommitdiff
path: root/src/serverenvironment.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-05-25 16:43:55 +0200
committerGitHub <noreply@github.com>2017-05-25 16:43:55 +0200
commit4d5ce8478c959a4ee5b13ef9ba7e46b28d089a21 (patch)
treed635cf0dfd7b5040c7c24378ac4c25e59cf48f61 /src/serverenvironment.cpp
parent5b338638e0e5743d8acfb48b72e17b671968722f (diff)
downloadminetest-4d5ce8478c959a4ee5b13ef9ba7e46b28d089a21.tar.gz
minetest-4d5ce8478c959a4ee5b13ef9ba7e46b28d089a21.tar.bz2
minetest-4d5ce8478c959a4ee5b13ef9ba7e46b28d089a21.zip
Enhance ABM performance a little bit by removing two std::set copy (#5815)
* Enhance ABM performance a little bit by removing two std::set copy * ActiveBlockModifier::getTriggerContents now returns a const ref * ActiveBlockModifier::getRequiredNeighbors now returns a const ref * ActiveBlockModifier::getRequiredNeighbors is now purely virtual * Little code style fix
Diffstat (limited to 'src/serverenvironment.cpp')
-rw-r--r--src/serverenvironment.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/serverenvironment.cpp b/src/serverenvironment.cpp
index 892c6c55b..cbdc747d1 100644
--- a/src/serverenvironment.cpp
+++ b/src/serverenvironment.cpp
@@ -721,7 +721,7 @@ public:
chance = 1;
ActiveABM aabm;
aabm.abm = abm;
- if(abm->getSimpleCatchUp()) {
+ if (abm->getSimpleCatchUp()) {
float intervals = actual_interval / trigger_interval;
if(intervals == 0)
continue;
@@ -731,25 +731,23 @@ public:
} else {
aabm.chance = chance;
}
+
// Trigger neighbors
- std::set<std::string> required_neighbors_s
- = abm->getRequiredNeighbors();
- for(std::set<std::string>::iterator
- i = required_neighbors_s.begin();
- i != required_neighbors_s.end(); ++i)
- {
- ndef->getIds(*i, aabm.required_neighbors);
+ const std::set<std::string> &required_neighbors_s =
+ abm->getRequiredNeighbors();
+ for (std::set<std::string>::iterator rn = required_neighbors_s.begin();
+ rn != required_neighbors_s.end(); ++rn) {
+ ndef->getIds(*rn, aabm.required_neighbors);
}
+
// Trigger contents
- std::set<std::string> contents_s = abm->getTriggerContents();
- for(std::set<std::string>::iterator
- i = contents_s.begin(); i != contents_s.end(); ++i)
- {
+ const std::set<std::string> &contents_s = abm->getTriggerContents();
+ for (std::set<std::string>::iterator cs = contents_s.begin();
+ cs != contents_s.end(); ++cs) {
std::set<content_t> ids;
- ndef->getIds(*i, ids);
- for(std::set<content_t>::const_iterator k = ids.begin();
- k != ids.end(); ++k)
- {
+ ndef->getIds(*cs, ids);
+ for (std::set<content_t>::const_iterator k = ids.begin();
+ k != ids.end(); ++k) {
content_t c = *k;
if (c >= m_aabms.size())
m_aabms.resize(c + 256, NULL);