Optimize parameter passing to avoid unnecessary copying

This commit is contained in:
Pugemon
2024-06-07 04:00:38 +03:00
parent 46ca1bb04a
commit f25a425cb9
123 changed files with 578 additions and 522 deletions
+4 -2
View File
@@ -1,5 +1,7 @@
#include "Block.hpp"
#include <utility>
#include "../core_defs.hpp"
#include "../util/stringutil.hpp"
@@ -38,7 +40,7 @@ const BlockRotProfile BlockRotProfile::PANE {"pane", {
{ { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }}, // West
}};
Block::Block(std::string name)
Block::Block(const std::string& name)
: name(name),
caption(util::id_to_caption(name)),
textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,
@@ -46,7 +48,7 @@ Block::Block(std::string name)
rotations(BlockRotProfile::PIPE)
{}
Block::Block(std::string name, std::string texture) : name(name),
Block::Block(std::string name, const std::string& texture) : name(std::move(name)),
textureFaces{texture,texture,texture,texture,texture,texture},
rotations(BlockRotProfile::PIPE)
{}
+2 -2
View File
@@ -186,8 +186,8 @@ public:
itemid_t pickingItem = 0;
} rt;
Block(std::string name);
Block(std::string name, std::string texture);
Block(const std::string& name);
Block(std::string name, const std::string& texture);
Block(const Block&) = delete;
};
+4 -2
View File
@@ -1,5 +1,7 @@
#include "Chunk.hpp"
#include <utility>
#include "voxel.hpp"
#include "../items/Inventory.hpp"
@@ -41,7 +43,7 @@ void Chunk::updateHeights() {
void Chunk::addBlockInventory(std::shared_ptr<Inventory> inventory,
uint x, uint y, uint z) {
inventories[vox_index(x, y, z)] = inventory;
inventories[vox_index(x, y, z)] = std::move(inventory);
flags.unsaved = true;
}
@@ -52,7 +54,7 @@ void Chunk::removeBlockInventory(uint x, uint y, uint z) {
}
void Chunk::setBlockInventories(chunk_inventories_map map) {
inventories = map;
inventories = std::move(map);
}
std::shared_ptr<Inventory> Chunk::getBlockInventory(uint x, uint y, uint z) const {
+1 -1
View File
@@ -480,7 +480,7 @@ void Chunks::_setOffset(int32_t x, int32_t z) {
oz = z;
}
bool Chunks::putChunk(std::shared_ptr<Chunk> chunk) {
bool Chunks::putChunk(const std::shared_ptr<Chunk>& chunk) {
int x = chunk->x;
int z = chunk->z;
x -= ox;
+1 -1
View File
@@ -36,7 +36,7 @@ public:
WorldFiles* worldFiles, LevelEvents* events, const Content* content);
~Chunks() = default;
bool putChunk(std::shared_ptr<Chunk> chunk);
bool putChunk(const std::shared_ptr<Chunk>& chunk);
Chunk* getChunk(int32_t x, int32_t z);
Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z);
+1 -1
View File
@@ -18,7 +18,7 @@ static debug::Logger logger("chunks-storage");
ChunksStorage::ChunksStorage(Level* level) : level(level) {
}
void ChunksStorage::store(std::shared_ptr<Chunk> chunk) {
void ChunksStorage::store(const std::shared_ptr<Chunk>& chunk) {
chunksMap[glm::ivec2(chunk->x, chunk->z)] = chunk;
}
+1 -1
View File
@@ -21,7 +21,7 @@ public:
~ChunksStorage() = default;
std::shared_ptr<Chunk> get(int x, int z) const;
void store(std::shared_ptr<Chunk> chunk);
void store(const std::shared_ptr<Chunk>& chunk);
void remove(int x, int y);
void getVoxels(VoxelsVolume* volume, bool backlight=false) const;
std::shared_ptr<Chunk> create(int x, int z);