diff options
author | sfan5 <sfan5@live.de> | 2021-04-05 13:38:31 +0200 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2021-10-20 14:25:39 +0100 |
commit | 83e26f839d28c5d9aa75aeab7d924fcaad445007 (patch) | |
tree | ff2617af2c8d2ca1b8742c64a28bd659def66743 /src/util/container.h | |
parent | c3f7905d82e5b1201d81378dedde746caf0e2451 (diff) | |
download | minetest-83e26f839d28c5d9aa75aeab7d924fcaad445007.tar.gz minetest-83e26f839d28c5d9aa75aeab7d924fcaad445007.tar.bz2 minetest-83e26f839d28c5d9aa75aeab7d924fcaad445007.zip |
Reserve vectors before pushing and other code quality changes (#11161)
Diffstat (limited to 'src/util/container.h')
-rw-r--r-- | src/util/container.h | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/util/container.h b/src/util/container.h index ea8c27bf8..001066563 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); @@ -158,7 +155,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; } @@ -171,7 +168,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; } @@ -185,7 +182,7 @@ public: MutexAutoLock lock(m_mutex); - T t = m_queue.front(); + T t = std::move(m_queue.front()); m_queue.pop_front(); return t; } @@ -195,7 +192,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; } @@ -211,7 +208,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; } @@ -225,7 +222,7 @@ public: MutexAutoLock lock(m_mutex); - T t = m_queue.back(); + T t = std::move(m_queue.back()); m_queue.pop_back(); return t; } |