From c72d9b806be3a95bca92007b0e515ae5e173681c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 18 Apr 2020 21:35:20 -0400 Subject: [PATCH] gl_shader_manager: std::move std::string where applicable Prevents unnecessary copies from occurring. In the case of ShaderCache, we can just remove the parameter, given it's unused. --- src/video_core/renderer_opengl/gl_shader_manager.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index d51e4be56..d232dceb4 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -229,7 +229,7 @@ public: return {cached_shader.GetHandle(), result}; } - void Inject(const KeyConfigType& key, std::string decomp, OGLProgram&& program) { + void Inject(const KeyConfigType& key, OGLProgram&& program) { OGLShaderStage stage{separable}; stage.Inject(std::move(program)); shaders.emplace(key, std::move(stage)); @@ -284,9 +284,9 @@ public: void Inject(const KeyConfigType& key, std::string decomp, OGLProgram&& program) { OGLShaderStage stage{separable}; stage.Inject(std::move(program)); - auto [iter, new_shader] = shader_cache.emplace(decomp, std::move(stage)); + const auto iter = shader_cache.emplace(std::move(decomp), std::move(stage)).first; OGLShaderStage& cached_shader = iter->second; - shader_map[key] = &cached_shader; + shader_map.insert_or_assign(key, &cached_shader); } private: @@ -518,8 +518,7 @@ void ShaderProgramManager::LoadDiskCache(const std::atomic_bool& stop_loading, } else if (raw.GetProgramType() == ProgramType::FS) { PicaFSConfig conf = PicaFSConfig::BuildFromRegs(raw.GetRawShaderConfig()); std::scoped_lock lock(mutex); - impl->fragment_shaders.Inject(conf, decomp->second.result.code, - std::move(shader)); + impl->fragment_shaders.Inject(conf, std::move(shader)); } else { // Unsupported shader type got stored somehow so nuke the cache