From 2faa68f9be475b6cccd7cf70dad84c1b0c0d2343 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sat, 21 Dec 2019 18:20:36 +0100 Subject: [PATCH] gs-effect: Pass unmodified parameters as const reference --- source/obs/gs/gs-effect.cpp | 12 ++++++------ source/obs/gs/gs-effect.hpp | 17 +++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/source/obs/gs/gs-effect.cpp b/source/obs/gs/gs-effect.cpp index 1bc7408..b7e5acd 100644 --- a/source/obs/gs/gs-effect.cpp +++ b/source/obs/gs/gs-effect.cpp @@ -54,7 +54,7 @@ static std::string load_file_as_code(std::filesystem::path file) return std::string(buf.data(), buf.data() + size); } -gs::effect::effect(std::string code, std::string name) +gs::effect::effect(const std::string& code, const std::string& name) { auto gctx = gs::context(); @@ -91,7 +91,7 @@ gs::effect_technique gs::effect::get_technique(size_t idx) return gs::effect_technique(get()->techniques.array + idx, this); } -gs::effect_technique gs::effect::get_technique(std::string name) +gs::effect_technique gs::effect::get_technique(const std::string& name) { for (size_t idx = 0; idx < count_techniques(); idx++) { auto ptr = get()->techniques.array + idx; @@ -103,7 +103,7 @@ gs::effect_technique gs::effect::get_technique(std::string name) return nullptr; } -bool gs::effect::has_technique(std::string name) +bool gs::effect::has_technique(const std::string& name) { if (get_technique(name)) return true; @@ -124,7 +124,7 @@ gs::effect_parameter gs::effect::get_parameter(size_t idx) return gs::effect_parameter(get()->params.array + idx, this); } -gs::effect_parameter gs::effect::get_parameter(std::string name) +gs::effect_parameter gs::effect::get_parameter(const std::string& name) { for (size_t idx = 0; idx < count_parameters(); idx++) { auto ptr = get()->params.array + idx; @@ -136,14 +136,14 @@ gs::effect_parameter gs::effect::get_parameter(std::string name) return nullptr; } -bool gs::effect::has_parameter(std::string name) +bool gs::effect::has_parameter(const std::string& name) { if (get_parameter(name)) return true; return false; } -bool gs::effect::has_parameter(std::string name, effect_parameter::type type) +bool gs::effect::has_parameter(const std::string& name, effect_parameter::type type) { auto eprm = get_parameter(name); if (eprm) diff --git a/source/obs/gs/gs-effect.hpp b/source/obs/gs/gs-effect.hpp index ea7e75a..60805df 100644 --- a/source/obs/gs/gs-effect.hpp +++ b/source/obs/gs/gs-effect.hpp @@ -42,20 +42,20 @@ namespace gs { class effect : public std::shared_ptr { public: effect(){}; - effect(std::string code, std::string name); + effect(const std::string& code, const std::string& name); effect(std::filesystem::path file); ~effect(); size_t count_techniques(); gs::effect_technique get_technique(size_t idx); - gs::effect_technique get_technique(std::string name); - bool has_technique(std::string name); + gs::effect_technique get_technique(const std::string& name); + bool has_technique(const std::string& name); size_t count_parameters(); gs::effect_parameter get_parameter(size_t idx); - gs::effect_parameter get_parameter(std::string name); - bool has_parameter(std::string name); - bool has_parameter(std::string name, effect_parameter::type type); + gs::effect_parameter get_parameter(const std::string& name); + bool has_parameter(const std::string& name); + bool has_parameter(const std::string& name, effect_parameter::type type); public /* Legacy Support */: inline gs_effect_t* get_object() @@ -63,11 +63,12 @@ namespace gs { return get(); } - static gs::effect create(std::string file) + static gs::effect create(const std::string& file) { return gs::effect(file); }; - static gs::effect create(std::string code, std::string name) + + static gs::effect create(const std::string& code, const std::string& name) { return gs::effect(code, name); };