From cf52d400eee2fc830c27b2a04ecc6df7461f267d Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Thu, 3 Dec 2020 13:19:55 +0900 Subject: [PATCH] use std::string_view to avoid shader string duplication. Change-Id: Iacad7e8c45d6176d2347c8ed423edd32e58de61f --- dali/internal/common/shader-data.h | 6 +++--- dali/internal/event/effects/shader-factory.cpp | 6 +++--- dali/internal/event/effects/shader-factory.h | 2 +- dali/internal/event/rendering/shader-impl.cpp | 8 ++++---- dali/internal/event/rendering/shader-impl.h | 6 +++--- dali/public-api/rendering/shader.cpp | 4 ++-- dali/public-api/rendering/shader.h | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/dali/internal/common/shader-data.h b/dali/internal/common/shader-data.h index 0dba6a1..97236e9 100644 --- a/dali/internal/common/shader-data.h +++ b/dali/internal/common/shader-data.h @@ -48,10 +48,10 @@ public: * @param[in] vertexSource Source code for vertex program * @param[in] fragmentSource Source code for fragment program */ - ShaderData(const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints) + ShaderData(std::string vertexSource, std::string fragmentSource, const Dali::Shader::Hint::Value hints) : mShaderHash( -1 ), - mVertexShader(vertexSource), - mFragmentShader(fragmentSource), + mVertexShader(std::move(vertexSource)), + mFragmentShader(std::move(fragmentSource)), mHints(hints) { } diff --git a/dali/internal/event/effects/shader-factory.cpp b/dali/internal/event/effects/shader-factory.cpp index c91f2ed..64aafe4 100644 --- a/dali/internal/event/effects/shader-factory.cpp +++ b/dali/internal/event/effects/shader-factory.cpp @@ -74,10 +74,10 @@ ShaderFactory::~ShaderFactory() } } -ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash ) +ShaderDataPtr ShaderFactory::Load( std::string_view vertexSource, std::string_view fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash ) { // Work out the filename for the binary that the glsl source will be compiled and linked to: - shaderHash = CalculateHash( vertexSource.c_str(), fragmentSource.c_str() ); + shaderHash = CalculateHash( vertexSource.data(), fragmentSource.data() ); std::string binaryShaderFilename; shaderBinaryFilename( shaderHash, binaryShaderFilename ); @@ -99,7 +99,7 @@ ShaderDataPtr ShaderFactory::Load( const std::string& vertexSource, const std::s if( shaderData.Get() == nullptr ) { // Allocate the structure that returns the loaded shader: - shaderData = new ShaderData( vertexSource, fragmentSource, hints ); + shaderData = new ShaderData( std::string(vertexSource), std::string(fragmentSource), hints ); shaderData->SetHashValue( shaderHash ); shaderData->GetBuffer().Clear(); diff --git a/dali/internal/event/effects/shader-factory.h b/dali/internal/event/effects/shader-factory.h index 6cf6cf9..12e0d2b 100644 --- a/dali/internal/event/effects/shader-factory.h +++ b/dali/internal/event/effects/shader-factory.h @@ -67,7 +67,7 @@ public: * a compiled shader program binary if one could be found, else an * empty binary buffer cleared to size zero. */ - Internal::ShaderDataPtr Load( const std::string& vertexSource, const std::string& fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash ); + Internal::ShaderDataPtr Load( std::string_view vertexSource, std::string_view fragmentSource, const Dali::Shader::Hint::Value hints, size_t& shaderHash ); /** * @brief Saves shader to memory cache and filesystem. diff --git a/dali/internal/event/rendering/shader-impl.cpp b/dali/internal/event/rendering/shader-impl.cpp index aa85ac7..35698d1 100644 --- a/dali/internal/event/rendering/shader-impl.cpp +++ b/dali/internal/event/rendering/shader-impl.cpp @@ -91,8 +91,8 @@ Property::Value HintString(const Dali::Shader::Hint::Value& hints) } // unnamed namespace -ShaderPtr Shader::New( const std::string& vertexShader, - const std::string& fragmentShader, +ShaderPtr Shader::New( std::string_view vertexShader, + std::string_view fragmentShader, Dali::Shader::Hint::Value hints ) { // create scene object first so it's guaranteed to exist for the event side @@ -195,8 +195,8 @@ Shader::Shader( const SceneGraph::Shader* sceneObject ) { } -void Shader::SetShader( const std::string& vertexSource, - const std::string& fragmentSource, +void Shader::SetShader( std::string_view vertexSource, + std::string_view fragmentSource, Dali::Shader::Hint::Value hints ) { // Try to load a pre-compiled shader binary for the source pair: diff --git a/dali/internal/event/rendering/shader-impl.h b/dali/internal/event/rendering/shader-impl.h index 9476f40..0f0940e 100644 --- a/dali/internal/event/rendering/shader-impl.h +++ b/dali/internal/event/rendering/shader-impl.h @@ -49,8 +49,8 @@ public: /** * @copydoc Dali::Shader::New() */ - static ShaderPtr New( const std::string& vertexShader, - const std::string& fragmentShader, + static ShaderPtr New( std::string_view vertexShader, + std::string_view fragmentShader, Dali::Shader::Hint::Value hints ); /** @@ -88,7 +88,7 @@ private: // implementation /** * Second stage initialization */ - void SetShader( const std::string& vertexShader, const std::string& fragmentShader, Dali::Shader::Hint::Value hints ); + void SetShader( std::string_view vertexShader, std::string_view fragmentShader, Dali::Shader::Hint::Value hints ); protected: /** diff --git a/dali/public-api/rendering/shader.cpp b/dali/public-api/rendering/shader.cpp index 9adf7de..c00bc8f 100644 --- a/dali/public-api/rendering/shader.cpp +++ b/dali/public-api/rendering/shader.cpp @@ -23,8 +23,8 @@ namespace Dali { -Shader Shader::New(const std::string& vertexShader, - const std::string& fragmentShader, +Shader Shader::New(std::string_view vertexShader, + std::string_view fragmentShader, Hint::Value hints) { Internal::ShaderPtr renderer = Internal::Shader::New(vertexShader, fragmentShader, hints); diff --git a/dali/public-api/rendering/shader.h b/dali/public-api/rendering/shader.h index f20c707..39604b8 100644 --- a/dali/public-api/rendering/shader.h +++ b/dali/public-api/rendering/shader.h @@ -124,8 +124,8 @@ public: * @param[in] hints Hints to define the geometry of the rendered object * @return A handle to a shader effect */ - static Shader New(const std::string& vertexShader, - const std::string& fragmentShader, + static Shader New(std::string_view vertexShader, + std::string_view fragmentShader, Hint::Value hints = Hint::NONE); /** -- 2.7.4