Skip to content

Commit

Permalink
Pass std::string_view by value
Browse files Browse the repository at this point in the history
  • Loading branch information
TLCFEM committed Nov 20, 2024
1 parent 825cc89 commit 1075c3c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Toolbox/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<Expression> SimpleScalarExpression::get_copy() const {
Expand All @@ -84,7 +84,7 @@ Mat<double> SimpleScalarExpression::gradient(const Col<double>& 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]);

Expand Down
6 changes: 3 additions & 3 deletions Toolbox/Expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> evaluate(double);
Expand All @@ -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<Expression> get_copy() const override;

Expand All @@ -86,7 +86,7 @@ class SimpleVectorExpression final : public Expression {
Col<double> y;

public:
SimpleVectorExpression(unsigned, const std::string_view&, const std::string_view&);
SimpleVectorExpression(unsigned, std::string_view, std::string_view);

[[nodiscard]] unique_ptr<Expression> get_copy() const override;

Expand Down
2 changes: 1 addition & 1 deletion Toolbox/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ string suanpan::to_lower(string&& U) {
return std::move(U);
}

std::vector<std::pair<string, unsigned>> suanpan::expression::split(const std::string_view& variable_string) {
std::vector<std::pair<string, unsigned>> suanpan::expression::split(const std::string_view variable_string) {
std::vector<std::string> variable_list;
auto I = variable_string.cbegin(), J = variable_string.cbegin();
while(I != variable_string.cend()) {
Expand Down
2 changes: 1 addition & 1 deletion Toolbox/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace suanpan {
string to_lower(string&&);

namespace expression {
std::vector<std::pair<string, unsigned>> split(const std::string_view& variable_string);
std::vector<std::pair<string, unsigned>> split(std::string_view variable_string);
} // namespace expression
} // namespace suanpan

Expand Down

0 comments on commit 1075c3c

Please sign in to comment.