fix: optimization: PVS-Studio warning V832

It's better to use '= default;' syntax instead of empty constructor and destructor body.
Using '= default;' can help the compiler generate more optimal code.

Reported by: PVS-Studio

Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov 2024-08-01 23:48:24 +03:00 committed by Pugemon
parent 73e721513c
commit 5dd7a15c09
No known key found for this signature in database
GPG Key ID: 472FA343B3CC3287
32 changed files with 38 additions and 58 deletions

View File

@ -1,7 +1,6 @@
#include "Assets.hpp" #include "Assets.hpp"
Assets::~Assets() { Assets::~Assets() = default;
}
const std::vector<TextureAnimation>& Assets::getAnimations() { const std::vector<TextureAnimation>& Assets::getAnimations() {
return animations; return animations;

View File

@ -68,7 +68,7 @@ class Assets {
std::unordered_map<std::type_index, assets_map> assets; std::unordered_map<std::type_index, assets_map> assets;
std::vector<assetload::setupfunc> setupFuncs; std::vector<assetload::setupfunc> setupFuncs;
public: public:
Assets() {} Assets() = default;
Assets(const Assets&) = delete; Assets(const Assets&) = delete;
~Assets(); ~Assets();

View File

@ -266,7 +266,7 @@ speakerid_t audio::play(
} }
auto speaker = speaker_ptr.get(); auto speaker = speaker_ptr.get();
speakerid_t id = nextId++; speakerid_t id = nextId++;
speakers.emplace(id, std::move(speaker_ptr)); speakers.try_emplace(id, std::move(speaker_ptr));
speaker->setPosition(position); speaker->setPosition(position);
speaker->setVolume(volume); speaker->setVolume(volume);
speaker->setPitch(pitch); speaker->setPitch(pitch);
@ -295,8 +295,8 @@ speakerid_t audio::play(
} }
auto speaker = speaker_ptr.get(); auto speaker = speaker_ptr.get();
speakerid_t id = nextId++; speakerid_t id = nextId++;
streams.emplace(id, stream); streams.try_emplace(id, stream);
speakers.emplace(id, std::move(speaker_ptr)); speakers.try_emplace(id, std::move(speaker_ptr));
stream->bindSpeaker(id); stream->bindSpeaker(id);
speaker->setPosition(position); speaker->setPosition(position);

View File

@ -23,7 +23,7 @@ namespace xml {
std::string name; std::string name;
std::string text; std::string text;
public: public:
Attribute() {}; Attribute() = default;
Attribute(std::string name, std::string text); Attribute(std::string name, std::string text);
const std::string& getName() const; const std::string& getName() const;

View File

@ -46,8 +46,7 @@ Content::Content(
} }
} }
Content::~Content() { Content::~Content() = default;
}
const rigging::SkeletonConfig* Content::getSkeleton(const std::string& id) const { const rigging::SkeletonConfig* Content::getSkeleton(const std::string& id) const {
auto found = skeletons.find(id); auto found = skeletons.find(id);

View File

@ -2,7 +2,7 @@
#include "../objects/rigging.hpp" #include "../objects/rigging.hpp"
ContentBuilder::~ContentBuilder() {} ContentBuilder::~ContentBuilder() = default;
void ContentBuilder::add(std::unique_ptr<ContentPackRuntime> pack) { void ContentBuilder::add(std::unique_ptr<ContentPackRuntime> pack) {
packs[pack->getId()] = std::move(pack); packs[pack->getId()] = std::move(pack);

View File

@ -142,5 +142,4 @@ ContentPackRuntime::ContentPackRuntime(
{ {
} }
ContentPackRuntime::~ContentPackRuntime() { ContentPackRuntime::~ContentPackRuntime() = default;
}

View File

@ -5,8 +5,7 @@
#include <queue> #include <queue>
#include <sstream> #include <sstream>
PacksManager::PacksManager() { PacksManager::PacksManager() = default;
}
void PacksManager::setSources(std::vector<fs::path> sources) { void PacksManager::setSources(std::vector<fs::path> sources) {
this->sources = sources; this->sources = sources;
@ -19,7 +18,7 @@ void PacksManager::scan() {
for (auto& folder : sources) { for (auto& folder : sources) {
ContentPack::scanFolder(folder, packsList); ContentPack::scanFolder(folder, packsList);
for (auto& pack : packsList) { for (auto& pack : packsList) {
packs.emplace(pack.id, pack); packs.try_emplace(pack.id, pack);
} }
} }
} }

View File

@ -41,7 +41,7 @@ namespace dynamic {
public: public:
std::vector<Value> values; std::vector<Value> values;
List() {} List() = default;
List(std::vector<Value> values) : values(std::move(values)) {} List(std::vector<Value> values) : values(std::move(values)) {}
std::string str(size_t index) const; std::string str(size_t index) const;
@ -79,7 +79,7 @@ namespace dynamic {
public: public:
std::unordered_map<std::string, Value> values; std::unordered_map<std::string, Value> values;
Map() {} Map() = default;
Map(std::unordered_map<std::string, Value> values) Map(std::unordered_map<std::string, Value> values)
: values(std::move(values)) {}; : values(std::move(values)) {};

View File

@ -47,8 +47,7 @@ WorldFiles::WorldFiles(const fs::path& directory, const DebugSettings& settings)
regions.doWriteLights = doWriteLights; regions.doWriteLights = doWriteLights;
} }
WorldFiles::~WorldFiles() { WorldFiles::~WorldFiles() = default;
}
void WorldFiles::createDirectories() { void WorldFiles::createDirectories() {
fs::create_directories(directory / fs::path("data")); fs::create_directories(directory / fs::path("data"));

View File

@ -56,8 +56,7 @@ WorldRegion::WorldRegion()
sizes(std::make_unique<uint32_t[]>(REGION_CHUNKS_COUNT)) sizes(std::make_unique<uint32_t[]>(REGION_CHUNKS_COUNT))
{} {}
WorldRegion::~WorldRegion() { WorldRegion::~WorldRegion() = default;
}
void WorldRegion::setUnsaved(bool unsaved) { void WorldRegion::setUnsaved(bool unsaved) {
this->unsaved = unsaved; this->unsaved = unsaved;
@ -98,8 +97,7 @@ WorldRegions::WorldRegions(const fs::path& directory) : directory(directory) {
layers[REGION_LAYER_ENTITIES].folder = directory/fs::path("entities"); layers[REGION_LAYER_ENTITIES].folder = directory/fs::path("entities");
} }
WorldRegions::~WorldRegions() { WorldRegions::~WorldRegions() = default;
}
WorldRegion* WorldRegions::getRegion(int x, int z, int layer) { WorldRegion* WorldRegions::getRegion(int x, int z, int layer) {
RegionsLayer& regions = layers[layer]; RegionsLayer& regions = layers[layer];

View File

@ -38,8 +38,7 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets) : conte
} }
} }
ContentGfxCache::~ContentGfxCache() { ContentGfxCache::~ContentGfxCache() = default;
}
const Content* ContentGfxCache::getContent() const { const Content* ContentGfxCache::getContent() const {
return content; return content;

View File

@ -81,8 +81,7 @@ LevelFrontend::LevelFrontend(
); );
} }
LevelFrontend::~LevelFrontend() { LevelFrontend::~LevelFrontend() = default;
}
Level* LevelFrontend::getLevel() const { Level* LevelFrontend::getLevel() const {
return level; return level;

View File

@ -19,8 +19,7 @@ Atlas::Atlas(
} }
} }
Atlas::~Atlas() { Atlas::~Atlas() = default;
}
void Atlas::prepare() { void Atlas::prepare() {
texture = Texture::from(image.get()); texture = Texture::from(image.get());

View File

@ -47,7 +47,7 @@ class AtlasBuilder {
std::vector<atlasentry> entries; std::vector<atlasentry> entries;
std::set<std::string> names; std::set<std::string> names;
public: public:
AtlasBuilder() {} AtlasBuilder() = default;
void add(const std::string& name, std::unique_ptr<ImageData> image); void add(const std::string& name, std::unique_ptr<ImageData> image);
bool has(const std::string& name) const; bool has(const std::string& name) const;
const std::set<std::string>& getNames() { return names; }; const std::set<std::string>& getNames() { return names; };

View File

@ -12,8 +12,7 @@ Font::Font(std::vector<std::unique_ptr<Texture>> pages, int lineHeight, int yoff
: lineHeight(lineHeight), yoffset(yoffset), pages(std::move(pages)) { : lineHeight(lineHeight), yoffset(yoffset), pages(std::move(pages)) {
} }
Font::~Font(){ Font::~Font() = default;
}
int Font::getYOffset() const { int Font::getYOffset() const {
return yoffset; return yoffset;

View File

@ -41,8 +41,7 @@ ImageData::ImageData(ImageFormat format, uint width, uint height, const ubyte* d
std::memcpy(this->data.get(), data, width * height * pixsize); std::memcpy(this->data.get(), data, width * height * pixsize);
} }
ImageData::~ImageData() { ImageData::~ImageData() = default;
}
void ImageData::flipX() { void ImageData::flipX() {
switch (format) { switch (format) {

View File

@ -18,8 +18,7 @@ PostProcessing::PostProcessing() {
quadMesh = std::make_unique<Mesh>(vertices, 6, attrs); quadMesh = std::make_unique<Mesh>(vertices, 6, attrs);
} }
PostProcessing::~PostProcessing() { PostProcessing::~PostProcessing() = default;
}
void PostProcessing::use(DrawContext& context) { void PostProcessing::use(DrawContext& context) {
const auto& vp = context.getViewport(); const auto& vp = context.getViewport();

View File

@ -32,7 +32,7 @@ uint Shader::getUniformLocation(const std::string& name) {
auto found = uniformLocations.find(name); auto found = uniformLocations.find(name);
if (found == uniformLocations.end()) { if (found == uniformLocations.end()) {
uint location = glGetUniformLocation(id, name.c_str()); uint location = glGetUniformLocation(id, name.c_str());
uniformLocations.emplace(name, location); uniformLocations.try_emplace(name, location);
return location; return location;
} }
return found->second; return found->second;

View File

@ -22,7 +22,7 @@ struct Frame {
class TextureAnimation { class TextureAnimation {
public: public:
TextureAnimation(Texture* srcTex, Texture* dstTex) : srcTexture(srcTex), dstTexture(dstTex) {}; TextureAnimation(Texture* srcTex, Texture* dstTex) : srcTexture(srcTex), dstTexture(dstTex) {};
~TextureAnimation() {}; ~TextureAnimation() = default;
void addFrame(const Frame& frame) { frames.emplace_back(frame); }; void addFrame(const Frame& frame) { frames.emplace_back(frame); };

View File

@ -64,8 +64,7 @@ ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
blank = Texture::from(&image); blank = Texture::from(&image);
} }
ModelBatch::~ModelBatch() { ModelBatch::~ModelBatch() = default;
}
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix, void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
const glm::mat3& rotation, glm::vec3 tint, const glm::mat3& rotation, glm::vec3 tint,

View File

@ -55,8 +55,7 @@ Skybox::Skybox(uint size, Shader* shader)
}); });
} }
Skybox::~Skybox() { Skybox::~Skybox() = default;
}
void Skybox::drawBackground(Camera* camera, Assets* assets, int width, int height) { void Skybox::drawBackground(Camera* camera, Assets* assets, int width, int height) {
auto backShader = assets->get<Shader>("background"); auto backShader = assets->get<Shader>("background");

View File

@ -75,8 +75,7 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
); );
} }
WorldRenderer::~WorldRenderer() { WorldRenderer::~WorldRenderer() = default;
}
bool WorldRenderer::drawChunk( bool WorldRenderer::drawChunk(
size_t index, size_t index,

View File

@ -44,8 +44,7 @@ GUI::GUI() {
container->add(tooltip); container->add(tooltip);
} }
GUI::~GUI() { GUI::~GUI() = default;
}
std::shared_ptr<Menu> GUI::getMenu() { std::shared_ptr<Menu> GUI::getMenu() {
return menu; return menu;

View File

@ -8,8 +8,7 @@
Inventories::Inventories(Level& level) : level(level) { Inventories::Inventories(Level& level) : level(level) {
} }
Inventories::~Inventories() { Inventories::~Inventories() = default;
}
std::shared_ptr<Inventory> Inventories::create(size_t size) { std::shared_ptr<Inventory> Inventories::create(size_t size) {
int64_t id = level.getWorld()->getNextInventoryId(); int64_t id = level.getWorld()->getNextInventoryId();

View File

@ -20,8 +20,7 @@ Lighting::Lighting(const Content* content, Chunks* chunks)
solverS = std::make_unique<LightSolver>(indices, chunks, 3); solverS = std::make_unique<LightSolver>(indices, chunks, 3);
} }
Lighting::~Lighting(){ Lighting::~Lighting() = default;
}
void Lighting::clear(){ void Lighting::clear(){
for (size_t index = 0; index < chunks->volume; index++){ for (size_t index = 0; index < chunks->volume; index++){

View File

@ -30,8 +30,7 @@ ChunksController::ChunksController(Level* level, uint padding)
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) { generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
} }
ChunksController::~ChunksController(){ ChunksController::~ChunksController() = default;
}
void ChunksController::update(int64_t maxDuration) { void ChunksController::update(int64_t maxDuration) {
int64_t mcstotal = 0; int64_t mcstotal = 0;

View File

@ -55,7 +55,7 @@ namespace cmd {
std::string description; std::string description;
executor_func executor; executor_func executor;
public: public:
Command() {} Command() = default;
Command( Command(
std::string name, std::string name,

View File

@ -5,7 +5,7 @@
class Frustum { class Frustum {
public: public:
Frustum() {}; Frustum() = default;
void update(glm::mat4 projview); void update(glm::mat4 projview);
bool isBoxVisible(const glm::vec3& minp, const glm::vec3& maxp) const; bool isBoxVisible(const glm::vec3& minp, const glm::vec3& maxp) const;

View File

@ -21,7 +21,7 @@ class AABBFaces {
public: public:
std::array<std::pair<rayvec3, rayvec2>, AABBFACES_COUNT> faces; // every face is min-point and opposite corner point std::array<std::pair<rayvec3, rayvec2>, AABBFACES_COUNT> faces; // every face is min-point and opposite corner point
AABBFaces(){}; AABBFaces() = default;
AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox); AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox);
}; };

View File

@ -28,8 +28,8 @@ struct ThreadPoolResult {
template<class T, class R> template<class T, class R>
class Worker { class Worker {
public: public:
Worker() {} Worker() = default;
virtual ~Worker() {} virtual ~Worker() = default;
virtual R operator()(const std::shared_ptr<T>&) = 0; virtual R operator()(const std::shared_ptr<T>&) = 0;
}; };

View File

@ -142,7 +142,7 @@ struct Binding {
bool state = false; bool state = false;
bool justChange = false; bool justChange = false;
Binding(){} Binding() = default;
Binding(inputtype type, int code) : type(type), code(code) {} Binding(inputtype type, int code) : type(type), code(code) {}
bool active() const { bool active() const {