fix: optimization: PVS-Studio warning V813

Passing large objects by const reference avoids unnecessary copying and enhances efficiency.

Reported by: PVS-Studio
Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov
2024-08-02 05:35:55 +03:00
committed by Pugemon
parent 5b325ac2bc
commit 2c1103307f
42 changed files with 173 additions and 144 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ struct CoordSystem {
void transform(AABB& aabb) const;
inline bool isVectorHasNegatives(glm::ivec3 vec) {
inline bool isVectorHasNegatives(const glm::ivec3& vec) {
return (vec.x < 0 || vec.y < 0 || vec.z < 0);
}
};
+6 -6
View File
@@ -232,13 +232,13 @@ void Chunks::repairSegments(const Block* def, blockstate state, int x, int y, in
}
}
bool Chunks::checkReplaceability(const Block* def, blockstate state, glm::ivec3 origin, blockid_t ignore) {
bool Chunks::checkReplaceability(const Block* def, blockstate state, const glm::ivec3 &coord, blockid_t ignore) {
const auto& rotation = def->rotations.variants[state.rotation];
const auto size = def->size;
for (int sy = 0; sy < size.y; sy++) {
for (int sz = 0; sz < size.z; sz++) {
for (int sx = 0; sx < size.x; sx++) {
auto pos = origin;
auto pos = coord;
pos += rotation.axisX * sx;
pos += rotation.axisY * sy;
pos += rotation.axisZ * sz;
@@ -257,7 +257,7 @@ bool Chunks::checkReplaceability(const Block* def, blockstate state, glm::ivec3
}
void Chunks::setRotationExtended(
Block* def, blockstate state, glm::ivec3 origin, uint8_t index
Block* def, blockstate state, const glm::ivec3 &origin, uint8_t index
) {
auto newstate = state;
newstate.rotation = index;
@@ -387,8 +387,8 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, blockstate state)
}
voxel* Chunks::rayCast(
glm::vec3 start,
glm::vec3 dir,
const glm::vec3 &start,
const glm::vec3 &dir,
float maxDist,
glm::vec3& end,
glm::ivec3& norm,
@@ -520,7 +520,7 @@ voxel* Chunks::rayCast(
return nullptr;
}
glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist) {
glm::vec3 Chunks::rayCastToObstacle(const glm::vec3 &start, const glm::vec3 &dir, float maxDist) {
const float px = start.x;
const float py = start.y;
const float pz = start.z;
+6 -6
View File
@@ -27,7 +27,7 @@ class Chunks {
void eraseSegments(const Block* def, blockstate state, int x, int y, int z);
void repairSegments(const Block* def, blockstate state, int x, int y, int z);
void setRotationExtended(Block* def, blockstate state, glm::ivec3 origin, uint8_t rotation);
void setRotationExtended(Block* def, blockstate state, const glm::ivec3 &origin, uint8_t rotation);
public:
std::vector<std::shared_ptr<Chunk>> chunks;
std::vector<std::shared_ptr<Chunk>> chunksSecond;
@@ -48,7 +48,7 @@ public:
Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z);
voxel* get(int32_t x, int32_t y, int32_t z) const;
inline voxel* get(glm::ivec3 pos) {
inline voxel* get(const glm::ivec3 &pos) {
return get(pos.x, pos.y, pos.z);
}
@@ -68,20 +68,20 @@ public:
/// @param state the block state
/// @param coord position of the zone start
/// @param ignore ignored block id (will be counted as replaceable)
bool checkReplaceability(const Block* def, blockstate state, glm::ivec3 coord, blockid_t ignore=0);
bool checkReplaceability(const Block* def, blockstate state, const glm::ivec3 &coord, blockid_t ignore=0);
void setRotation(int32_t x, int32_t y, int32_t z, uint8_t rotation);
voxel* rayCast(
glm::vec3 start,
glm::vec3 dir,
const glm::vec3 &start,
const glm::vec3 &dir,
float maxLength,
glm::vec3& end,
glm::ivec3& norm,
glm::ivec3& iend
);
glm::vec3 rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist);
glm::vec3 rayCastToObstacle(const glm::vec3 &start, const glm::vec3 &dir, float maxDist);
const AABB* isObstacleAt(float x, float y, float z);
bool isSolidBlock(int32_t x, int32_t y, int32_t z);