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-03 17:44:51 +03:00
committed by MihailRis
parent 35ef339b0c
commit a20ffee7cb
2 changed files with 9 additions and 9 deletions
+7 -7
View File
@@ -252,11 +252,11 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
if (boxarr->size() == 7) if (boxarr->size() == 7)
for (uint j = 6; j < 12; j++) { 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) else if (boxarr->size() == 12)
for (uint j = 6; j < 12; j++) { for (uint j = 6; j < 12; j++) {
def.modelTextures.push_back(boxarr->str(j)); def.modelTextures.emplace_back(boxarr->str(j));
} }
else else
for (uint j = 6; j < 12; j++) { for (uint j = 6; j < 12; j++) {
@@ -277,7 +277,7 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
def.modelExtraPoints.push_back(p1+xw+yh); def.modelExtraPoints.push_back(p1+xw+yh);
def.modelExtraPoints.push_back(p1+yh); def.modelExtraPoints.push_back(p1+yh);
def.modelTextures.push_back(tgonobj->str(9)); def.modelTextures.emplace_back(tgonobj->str(9));
} }
} }
} }
@@ -314,7 +314,7 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
auto root = files::read_json(file); auto root = files::read_json(file);
if (auto componentsarr = root->list("components")) { if (auto componentsarr = root->list("components")) {
for (size_t i = 0; i < componentsarr->size(); i++) { 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")) { if (auto boxarr = root->list("hitbox")) {
@@ -325,12 +325,12 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
if (auto sensorarr = sensorsarr->list(i)) { if (auto sensorarr = sensorsarr->list(i)) {
auto sensorType = sensorarr->str(0); auto sensorType = sensorarr->str(0);
if (sensorType == "aabb") { 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(1), sensorarr->num(2), sensorarr->num(3)},
{sensorarr->num(4), sensorarr->num(5), sensorarr->num(6)} {sensorarr->num(4), sensorarr->num(5), sensorarr->num(6)}
}}); });
} else if (sensorType == "radius") { } else if (sensorType == "radius") {
def.radialSensors.push_back({i, sensorarr->num(1)}); def.radialSensors.emplace_back(i, sensorarr->num(1));
} else { } else {
logger.error() << name << ": sensor #" << i << " - unknown type " logger.error() << name << ": sensor #" << i << " - unknown type "
<< util::quote(sensorType); << util::quote(sensorType);
+2 -2
View File
@@ -214,7 +214,7 @@ std::vector<std::string> ResPaths::listdirRaw(const std::string& folderName) con
continue; continue;
for (const auto& entry : fs::directory_iterator(folder)) { for (const auto& entry : fs::directory_iterator(folder)) {
auto name = entry.path().filename().u8string(); 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; return entries;
for (const auto& entry : fs::directory_iterator(folder)) { for (const auto& entry : fs::directory_iterator(folder)) {
auto name = entry.path().filename().u8string(); auto name = entry.path().filename().u8string();
entries.push_back("core:"+folderName+"/"+name); entries.emplace_back("core:"+folderName+"/"+name);
} }
} }
return entries; return entries;