fix: optimization: PVS-Studio warning V823

Replaced 'push_back' with 'emplace_back' for better performance in containers.

Reported by: PVS-Studio

Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov 2024-08-02 00:14:36 +03:00 committed by Pugemon
parent 818fd716cc
commit 7fbd32b8df
No known key found for this signature in database
GPG Key ID: 472FA343B3CC3287
2 changed files with 9 additions and 9 deletions

View File

@ -251,11 +251,11 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
if (boxarr->size() == 7)
for (uint j = 6; j < 12; j++) {
def.modelTextures.push_back(boxarr->str(6));
def.modelTextures.emplace_back(boxarr->str(6));
}
else if (boxarr->size() == 12)
for (uint j = 6; j < 12; j++) {
def.modelTextures.push_back(boxarr->str(j));
def.modelTextures.emplace_back(boxarr->str(j));
}
else
for (uint j = 6; j < 12; j++) {
@ -276,7 +276,7 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
def.modelExtraPoints.push_back(p1+xw+yh);
def.modelExtraPoints.push_back(p1+yh);
def.modelTextures.push_back(tgonobj->str(9));
def.modelTextures.emplace_back(tgonobj->str(9));
}
}
}
@ -313,7 +313,7 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
auto root = files::read_json(file);
if (auto componentsarr = root->list("components")) {
for (size_t i = 0; i < componentsarr->size(); i++) {
def.components.push_back(componentsarr->str(i));
def.components.emplace_back(componentsarr->str(i));
}
}
if (auto boxarr = root->list("hitbox")) {
@ -324,12 +324,12 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
if (auto sensorarr = sensorsarr->list(i)) {
auto sensorType = sensorarr->str(0);
if (sensorType == "aabb") {
def.boxSensors.push_back({i, {
def.boxSensors.emplace_back(i, AABB{
{sensorarr->num(1), sensorarr->num(2), sensorarr->num(3)},
{sensorarr->num(4), sensorarr->num(5), sensorarr->num(6)}
}});
});
} else if (sensorType == "radius") {
def.radialSensors.push_back({i, sensorarr->num(1)});
def.radialSensors.emplace_back(i, sensorarr->num(1));
} else {
logger.error() << name << ": sensor #" << i << " - unknown type "
<< util::quote(sensorType);

View File

@ -214,7 +214,7 @@ std::vector<std::string> ResPaths::listdirRaw(const std::string& folderName) con
continue;
for (const auto& entry : fs::directory_iterator(folder)) {
auto name = entry.path().filename().u8string();
entries.push_back(root.name+":"+folderName+"/"+name);
entries.emplace_back(root.name+":"+folderName+"/"+name);
}
}
{
@ -223,7 +223,7 @@ std::vector<std::string> ResPaths::listdirRaw(const std::string& folderName) con
return entries;
for (const auto& entry : fs::directory_iterator(folder)) {
auto name = entry.path().filename().u8string();
entries.push_back("core:"+folderName+"/"+name);
entries.emplace_back("core:"+folderName+"/"+name);
}
}
return entries;