From 1075c3ca262d4b31949ac42f89984d8bae1c2754 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Wed, 20 Nov 2024 22:06:31 +0100 Subject: [PATCH] Pass `std::string_view` by value --- Toolbox/Expression.cpp | 6 +++--- Toolbox/Expression.h | 6 +++--- Toolbox/utility.cpp | 2 +- Toolbox/utility.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Toolbox/Expression.cpp b/Toolbox/Expression.cpp index 84df06356..a9430fb63 100644 --- a/Toolbox/Expression.cpp +++ b/Toolbox/Expression.cpp @@ -43,7 +43,7 @@ uword Expression::input_size() const { return x.n_elem; } uword Expression::output_size() const { return 1; } -bool Expression::compile(const std::string_view& expression_string) { +bool Expression::compile(const std::string_view expression_string) { expression.register_symbol_table(symbol_table); std::scoped_lock lock{parser_mutex}; return parser.compile(expression_text = expression_string, expression); @@ -59,7 +59,7 @@ void Expression::print() { suanpan_info("An expression represents \"{}\".", expression_text); } -SimpleScalarExpression::SimpleScalarExpression(const unsigned tag, const std::string_view& input_string) +SimpleScalarExpression::SimpleScalarExpression(const unsigned tag, const std::string_view input_string) : Expression(tag, {std::string{input_string}}) {} unique_ptr SimpleScalarExpression::get_copy() const { @@ -84,7 +84,7 @@ Mat SimpleScalarExpression::gradient(const Col& in_x) { return result; } -SimpleVectorExpression::SimpleVectorExpression(const unsigned tag, const std::string_view& input_string, const std::string_view& output_string) +SimpleVectorExpression::SimpleVectorExpression(const unsigned tag, const std::string_view input_string, const std::string_view output_string) : Expression(tag, {std::string{input_string}, std::string{output_string}}) { const auto variable_list = suanpan::expression::split(variable_text_list[1]); diff --git a/Toolbox/Expression.h b/Toolbox/Expression.h index 2869685e2..d955b7816 100644 --- a/Toolbox/Expression.h +++ b/Toolbox/Expression.h @@ -59,7 +59,7 @@ class Expression : public Tag { [[nodiscard]] virtual uword input_size() const; [[nodiscard]] virtual uword output_size() const; - bool compile(const std::string_view&); + bool compile(std::string_view); static std::string error(); Mat evaluate(double); @@ -73,7 +73,7 @@ class Expression : public Tag { class SimpleScalarExpression final : public Expression { public: - SimpleScalarExpression(unsigned, const std::string_view&); + SimpleScalarExpression(unsigned, std::string_view); [[nodiscard]] unique_ptr get_copy() const override; @@ -86,7 +86,7 @@ class SimpleVectorExpression final : public Expression { Col y; public: - SimpleVectorExpression(unsigned, const std::string_view&, const std::string_view&); + SimpleVectorExpression(unsigned, std::string_view, std::string_view); [[nodiscard]] unique_ptr get_copy() const override; diff --git a/Toolbox/utility.cpp b/Toolbox/utility.cpp index ba2fed804..f07b13a58 100644 --- a/Toolbox/utility.cpp +++ b/Toolbox/utility.cpp @@ -66,7 +66,7 @@ string suanpan::to_lower(string&& U) { return std::move(U); } -std::vector> suanpan::expression::split(const std::string_view& variable_string) { +std::vector> suanpan::expression::split(const std::string_view variable_string) { std::vector variable_list; auto I = variable_string.cbegin(), J = variable_string.cbegin(); while(I != variable_string.cend()) { diff --git a/Toolbox/utility.h b/Toolbox/utility.h index ae3eebfbc..2b93f59df 100644 --- a/Toolbox/utility.h +++ b/Toolbox/utility.h @@ -72,7 +72,7 @@ namespace suanpan { string to_lower(string&&); namespace expression { - std::vector> split(const std::string_view& variable_string); + std::vector> split(std::string_view variable_string); } // namespace expression } // namespace suanpan