mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Reserve vectors before pushing and other code quality changes (#11161)
This commit is contained in:
parent
3e1904fa8c
commit
f0bad0e2ba
20 changed files with 106 additions and 108 deletions
|
@ -206,10 +206,9 @@ NodeMetadataList::~NodeMetadataList()
|
|||
std::vector<v3s16> NodeMetadataList::getAllKeys()
|
||||
{
|
||||
std::vector<v3s16> keys;
|
||||
|
||||
NodeMetadataMap::const_iterator it;
|
||||
for (it = m_data.begin(); it != m_data.end(); ++it)
|
||||
keys.push_back(it->first);
|
||||
keys.reserve(m_data.size());
|
||||
for (const auto &it : m_data)
|
||||
keys.push_back(it.first);
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
@ -218,7 +217,7 @@ NodeMetadata *NodeMetadataList::get(v3s16 p)
|
|||
{
|
||||
NodeMetadataMap::const_iterator n = m_data.find(p);
|
||||
if (n == m_data.end())
|
||||
return NULL;
|
||||
return nullptr;
|
||||
return n->second;
|
||||
}
|
||||
|
||||
|
@ -235,7 +234,7 @@ void NodeMetadataList::remove(v3s16 p)
|
|||
void NodeMetadataList::set(v3s16 p, NodeMetadata *d)
|
||||
{
|
||||
remove(p);
|
||||
m_data.insert(std::make_pair(p, d));
|
||||
m_data.emplace(p, d);
|
||||
}
|
||||
|
||||
void NodeMetadataList::clear()
|
||||
|
@ -251,9 +250,8 @@ void NodeMetadataList::clear()
|
|||
int NodeMetadataList::countNonEmpty() const
|
||||
{
|
||||
int n = 0;
|
||||
NodeMetadataMap::const_iterator it;
|
||||
for (it = m_data.begin(); it != m_data.end(); ++it) {
|
||||
if (!it->second->empty())
|
||||
for (const auto &it : m_data) {
|
||||
if (!it.second->empty())
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue