summaryrefslogtreecommitdiff
path: root/src/util/container.h
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-04-05 13:38:31 +0200
committerGitHub <noreply@github.com>2021-04-05 13:38:31 +0200
commitf0bad0e2badbb7d4777aac7de1b50239bca4010a (patch)
tree4c3115a42ac86e9a64d9e5f088fe187022885779 /src/util/container.h
parent3e1904fa8c4aae3448d58b7e60545a4fdd8234f3 (diff)
downloadminetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.tar.gz
minetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.tar.bz2
minetest-f0bad0e2badbb7d4777aac7de1b50239bca4010a.zip
Reserve vectors before pushing and other code quality changes (#11161)
Diffstat (limited to 'src/util/container.h')
-rw-r--r--src/util/container.h23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/util/container.h b/src/util/container.h
index 2ad2bbfc7..1c4a219f0 100644
--- a/src/util/container.h
+++ b/src/util/container.h
@@ -90,8 +90,7 @@ public:
bool get(const Key &name, Value *result) const
{
MutexAutoLock lock(m_mutex);
- typename std::map<Key, Value>::const_iterator n =
- m_values.find(name);
+ auto n = m_values.find(name);
if (n == m_values.end())
return false;
if (result)
@@ -103,11 +102,9 @@ public:
{
MutexAutoLock lock(m_mutex);
std::vector<Value> result;
- for (typename std::map<Key, Value>::const_iterator
- it = m_values.begin();
- it != m_values.end(); ++it){
+ result.reserve(m_values.size());
+ for (auto it = m_values.begin(); it != m_values.end(); ++it)
result.push_back(it->second);
- }
return result;
}
@@ -136,7 +133,7 @@ public:
return m_queue.empty();
}
- void push_back(T t)
+ void push_back(const T &t)
{
MutexAutoLock lock(m_mutex);
m_queue.push_back(t);
@@ -151,7 +148,7 @@ public:
if (m_signal.wait(wait_time_max_ms)) {
MutexAutoLock lock(m_mutex);
- T t = m_queue.front();
+ T t = std::move(m_queue.front());
m_queue.pop_front();
return t;
}
@@ -164,7 +161,7 @@ public:
if (m_signal.wait(wait_time_max_ms)) {
MutexAutoLock lock(m_mutex);
- T t = m_queue.front();
+ T t = std::move(m_queue.front());
m_queue.pop_front();
return t;
}
@@ -178,7 +175,7 @@ public:
MutexAutoLock lock(m_mutex);
- T t = m_queue.front();
+ T t = std::move(m_queue.front());
m_queue.pop_front();
return t;
}
@@ -188,7 +185,7 @@ public:
if (m_signal.wait(wait_time_max_ms)) {
MutexAutoLock lock(m_mutex);
- T t = m_queue.back();
+ T t = std::move(m_queue.back());
m_queue.pop_back();
return t;
}
@@ -204,7 +201,7 @@ public:
if (m_signal.wait(wait_time_max_ms)) {
MutexAutoLock lock(m_mutex);
- T t = m_queue.back();
+ T t = std::move(m_queue.back());
m_queue.pop_back();
return t;
}
@@ -218,7 +215,7 @@ public:
MutexAutoLock lock(m_mutex);
- T t = m_queue.back();
+ T t = std::move(m_queue.back());
m_queue.pop_back();
return t;
}