Optimize parameter passing to avoid unnecessary copying
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "../util/stringutil.hpp"
|
||||
#include "../typedefs.hpp"
|
||||
@@ -21,7 +22,7 @@ fs::path EnginePaths::getResources() const {
|
||||
return resources;
|
||||
}
|
||||
|
||||
fs::path EnginePaths::getScreenshotFile(std::string ext) {
|
||||
fs::path EnginePaths::getScreenshotFile(const std::string& ext) {
|
||||
fs::path folder = userfiles/fs::path(SCREENSHOTS_FOLDER);
|
||||
if (!fs::is_directory(folder)) {
|
||||
fs::create_directory(folder);
|
||||
@@ -75,11 +76,11 @@ std::vector<fs::path> EnginePaths::scanForWorlds() {
|
||||
if (!fs::is_directory(folder))
|
||||
return folders;
|
||||
|
||||
for (auto entry : fs::directory_iterator(folder)) {
|
||||
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||
if (!entry.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
fs::path worldFolder = entry.path();
|
||||
const fs::path& worldFolder = entry.path();
|
||||
fs::path worldFile = worldFolder/fs::u8path(WorldFiles::WORLD_FILE);
|
||||
if (!fs::is_regular_file(worldFile)) {
|
||||
continue;
|
||||
@@ -94,20 +95,20 @@ std::vector<fs::path> EnginePaths::scanForWorlds() {
|
||||
return folders;
|
||||
}
|
||||
|
||||
bool EnginePaths::isWorldNameUsed(std::string name) {
|
||||
bool EnginePaths::isWorldNameUsed(const std::string& name) {
|
||||
return fs::exists(EnginePaths::getWorldsFolder()/fs::u8path(name));
|
||||
}
|
||||
|
||||
void EnginePaths::setUserfiles(fs::path folder) {
|
||||
this->userfiles = folder;
|
||||
this->userfiles = std::move(folder);
|
||||
}
|
||||
|
||||
void EnginePaths::setResources(fs::path folder) {
|
||||
this->resources = folder;
|
||||
this->resources = std::move(folder);
|
||||
}
|
||||
|
||||
void EnginePaths::setWorldFolder(fs::path folder) {
|
||||
this->worldFolder = folder;
|
||||
this->worldFolder = std::move(folder);
|
||||
}
|
||||
|
||||
void EnginePaths::setContentPacks(std::vector<ContentPack>* contentPacks) {
|
||||
@@ -139,7 +140,7 @@ static fs::path toCanonic(fs::path path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
fs::path EnginePaths::resolve(std::string path, bool throwErr) {
|
||||
fs::path EnginePaths::resolve(const std::string& path, bool throwErr) {
|
||||
size_t separator = path.find(':');
|
||||
if (separator == std::string::npos) {
|
||||
throw files_access_error("no entry point specified");
|
||||
@@ -172,7 +173,7 @@ fs::path EnginePaths::resolve(std::string path, bool throwErr) {
|
||||
}
|
||||
|
||||
ResPaths::ResPaths(fs::path mainRoot, std::vector<PathsRoot> roots)
|
||||
: mainRoot(mainRoot), roots(roots) {
|
||||
: mainRoot(std::move(mainRoot)), roots(std::move(roots)) {
|
||||
}
|
||||
|
||||
fs::path ResPaths::find(const std::string& filename) const {
|
||||
|
||||
Reference in New Issue
Block a user