Skip to content

Commit

Permalink
[SUTK] Use const std::string_view where the intention is only to read…
Browse files Browse the repository at this point in the history
… to avoid temporary instantiations of std::string objects.
  • Loading branch information
ravi688 committed Oct 26, 2024
1 parent 176bfa6 commit 6043fc2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions include/sge-cpp/ShaderLibrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ namespace SGE
return Shader(shader);
}

Shader compileAndLoadShader(const std::string_view source, const std::string& name) const noexcept
// name: should be null-terminated
Shader compileAndLoadShader(const std::string_view source, const std::string_view name) const noexcept
{
auto handle = shader_library_compile_and_load_shader(m_handle, source.data(), name.c_str());
auto handle = shader_library_compile_and_load_shader(m_handle, source.data(), name.data());
shader_t* shader = shader_library_getH(m_handle, handle);
return Shader(shader);
}
Expand All @@ -36,9 +37,15 @@ namespace SGE
return Shader(shader);
}

Shader getShader(const std::string& name) noexcept
Shader getShader(const std::string& name) noexcept
{
shader_handle_t handle = shader_library_get_handle(m_handle, name.c_str());
return getShader(static_cast<const std::string_view>(name));
}

// name: should be null-terminated
Shader getShader(const std::string_view name) noexcept
{
shader_handle_t handle = shader_library_get_handle(m_handle, name.data());
if(handle == SHADER_HANDLE_INVALID)
return Shader { };
else
Expand Down

0 comments on commit 6043fc2

Please sign in to comment.