From 55c72ecb296b19fdc96c77af0573631ae4c0afd7 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 16 Aug 2025 13:49:07 +0200 Subject: [PATCH] Use string_view in components/fx --- components/fx/lexer.cpp | 2 +- components/fx/lexer.hpp | 2 +- components/fx/technique.cpp | 14 +++++++------- components/fx/technique.hpp | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/components/fx/lexer.cpp b/components/fx/lexer.cpp index 4369febbcb..39cad9970a 100644 --- a/components/fx/lexer.cpp +++ b/components/fx/lexer.cpp @@ -120,7 +120,7 @@ namespace Fx return mLastJumpBlock; } - [[noreturn]] void Lexer::error(const std::string& msg) + [[noreturn]] void Lexer::error(std::string_view msg) { throw LexerException(std::format("Line {} Col {}. {}", mLine + 1, mColumn, msg)); } diff --git a/components/fx/lexer.hpp b/components/fx/lexer.hpp index 1b32298608..f49dbcd694 100644 --- a/components/fx/lexer.hpp +++ b/components/fx/lexer.hpp @@ -46,7 +46,7 @@ namespace Fx Block getLastJumpBlock() const; - [[noreturn]] void error(const std::string& msg); + [[noreturn]] void error(std::string_view msg); private: void drop(); diff --git a/components/fx/technique.cpp b/components/fx/technique.cpp index b675e7ddad..38db49bc7a 100644 --- a/components/fx/technique.cpp +++ b/components/fx/technique.cpp @@ -95,10 +95,10 @@ namespace Fx return std::format("\n#line {}\n{}\n", block.line + 1, block.content); } - Technique::UniformMap::iterator Technique::findUniform(const std::string& name) + Technique::UniformMap::iterator Technique::findUniform(std::string_view name) { return std::find_if(mDefinedUniforms.begin(), mDefinedUniforms.end(), - [&name](const auto& uniform) { return uniform->mName == name; }); + [=](const auto& uniform) { return uniform->mName == name; }); } bool Technique::compile() @@ -201,7 +201,7 @@ namespace Fx return isDirty; } - [[noreturn]] void Technique::error(const std::string& msg) + [[noreturn]] void Technique::error(std::string_view msg) { mLexer->error(msg); } @@ -405,7 +405,7 @@ namespace Fx template void Technique::parseSampler() { - if (findUniform(std::string(mBlockName)) != mDefinedUniforms.end()) + if (findUniform(mBlockName) != mDefinedUniforms.end()) error(std::format("redeclaration of uniform '{}'", mBlockName)); ProxyTextureData proxy; @@ -530,7 +530,7 @@ namespace Fx template void Technique::parseUniform() { - if (findUniform(std::string(mBlockName)) != mDefinedUniforms.end()) + if (findUniform(mBlockName) != mDefinedUniforms.end()) error(std::format("redeclaration of uniform '{}'", mBlockName)); std::shared_ptr uniform = std::make_shared(); @@ -671,7 +671,7 @@ namespace Fx } template - void Technique::expect(const std::string& err) + void Technique::expect(std::string_view err) { mToken = mLexer->next(); if (!std::holds_alternative(mToken)) @@ -684,7 +684,7 @@ namespace Fx } template - void Technique::expect(const std::string& err) + void Technique::expect(std::string_view err) { mToken = mLexer->next(); if (!std::holds_alternative(mToken) && !std::holds_alternative(mToken)) diff --git a/components/fx/technique.hpp b/components/fx/technique.hpp index ebf3fe30f5..3db46447dd 100644 --- a/components/fx/technique.hpp +++ b/components/fx/technique.hpp @@ -172,7 +172,7 @@ namespace Fx std::string getLastError() const { return mLastError; } - UniformMap::iterator findUniform(const std::string& name); + UniformMap::iterator findUniform(std::string_view name); bool getDynamic() const { return mDynamic; } @@ -183,17 +183,17 @@ namespace Fx bool getInternal() const { return mInternal; } private: - [[noreturn]] void error(const std::string& msg); + [[noreturn]] void error(std::string_view msg); void clear(); std::string_view asLiteral() const; template - void expect(const std::string& err = ""); + void expect(std::string_view err = {}); template - void expect(const std::string& err = ""); + void expect(std::string_view err = {}); template bool isNext();