From e044397e887abdec1ad3226a55b3119ab9923f7d Mon Sep 17 00:00:00 2001 From: Riyyi Date: Wed, 10 Feb 2021 14:36:19 +0100 Subject: [PATCH] Omit copy constructors for strings in constructors --- inferno/src/inferno/component/luascriptcomponent.h | 5 +++-- inferno/src/inferno/component/tagcomponent.h | 3 ++- inferno/src/inferno/render/font.cpp | 6 ++++-- inferno/src/inferno/render/gltf.cpp | 2 +- inferno/src/inferno/render/shader.cpp | 6 ++++-- inferno/src/inferno/render/texture.cpp | 4 +++- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/inferno/src/inferno/component/luascriptcomponent.h b/inferno/src/inferno/component/luascriptcomponent.h index a666afe..d6fe1b9 100644 --- a/inferno/src/inferno/component/luascriptcomponent.h +++ b/inferno/src/inferno/component/luascriptcomponent.h @@ -1,7 +1,8 @@ #ifndef LUA_SCRIPT_COMPONENT_H #define LUA_SCRIPT_COMPONENT_H -#include // std::string +#include // std::string +#include // std::move namespace Inferno { @@ -14,7 +15,7 @@ namespace Inferno { // Dont allow manually setting instance during construction LuaScriptComponent() {} LuaScriptComponent(const std::string& path) - : path(path) {} + : path(std::move(path)) {} }; } diff --git a/inferno/src/inferno/component/tagcomponent.h b/inferno/src/inferno/component/tagcomponent.h index 74c2a9e..5f2035c 100644 --- a/inferno/src/inferno/component/tagcomponent.h +++ b/inferno/src/inferno/component/tagcomponent.h @@ -2,6 +2,7 @@ #define TAG_COMPONENT_H #include // std::string +#include // std::move namespace Inferno { @@ -10,7 +11,7 @@ namespace Inferno { TagComponent() = default; TagComponent(const std::string& tag) - : tag(tag) {} + : tag(std::move(tag)) {} operator const std::string&() const { return tag; } }; diff --git a/inferno/src/inferno/render/font.cpp b/inferno/src/inferno/render/font.cpp index f42f8a5..e34f272 100644 --- a/inferno/src/inferno/render/font.cpp +++ b/inferno/src/inferno/render/font.cpp @@ -1,5 +1,6 @@ -#include // std::numeric_limits -#include // std::getline, std::stoi +#include // std::numeric_limits +#include // std::getline, std::stoi +#include // std::move #include "inferno/assert.h" #include "inferno/io/file.h" @@ -10,6 +11,7 @@ namespace Inferno { Font::Font(const std::string& name) + : m_name(std::move(name)) { std::string path = name + ".fnt"; std::string image = name + ".png"; diff --git a/inferno/src/inferno/render/gltf.cpp b/inferno/src/inferno/render/gltf.cpp index f98d74d..8608f4c 100644 --- a/inferno/src/inferno/render/gltf.cpp +++ b/inferno/src/inferno/render/gltf.cpp @@ -13,7 +13,7 @@ namespace Inferno { Gltf::Gltf(const std::string& path) - : m_path(path) + : m_path(std::move(path)) { auto gltf = GltfFile::read(path); ASSERT(gltf.first, "Gltf model invalid JSON content '{}'", path); diff --git a/inferno/src/inferno/render/shader.cpp b/inferno/src/inferno/render/shader.cpp index 5bab00c..1d87c1b 100644 --- a/inferno/src/inferno/render/shader.cpp +++ b/inferno/src/inferno/render/shader.cpp @@ -1,4 +1,5 @@ -#include // std::vector +#include // std::move +#include // std::vector #include "glad/glad.h" #include "glm/gtc/type_ptr.hpp" // glm::value_ptr @@ -12,7 +13,8 @@ namespace Inferno { Shader::Shader(const std::string& name) - : m_id(0) + : m_name(std::move(name)), + m_id(0) { // Get file contents std::string vertexSrc = File::read(name + ".vert"); diff --git a/inferno/src/inferno/render/texture.cpp b/inferno/src/inferno/render/texture.cpp index 97ad200..b346d39 100644 --- a/inferno/src/inferno/render/texture.cpp +++ b/inferno/src/inferno/render/texture.cpp @@ -1,5 +1,6 @@ #include // UINT_MAX -#include +#include // std::shared_ptr +#include // std::move #include "glad/glad.h" #define STB_IMAGE_IMPLEMENTATION @@ -11,6 +12,7 @@ namespace Inferno { Texture::Texture(const std::string& path) + : m_path(std::move(path)) { int width; int height;