Merge pull request #12400 from lioncash/expparse

ExpressionParser: Get rid of some redundant copies
This commit is contained in:
Tilka 2023-12-12 19:17:29 +00:00 committed by GitHub
commit 87b44a2fb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -248,7 +248,7 @@ ParseStatus Lexer::Tokenize(std::vector<Token>& tokens)
class ControlExpression : public Expression class ControlExpression : public Expression
{ {
public: public:
explicit ControlExpression(ControlQualifier qualifier) : m_qualifier(qualifier) {} explicit ControlExpression(ControlQualifier qualifier) : m_qualifier(std::move(qualifier)) {}
ControlState GetValue() const override ControlState GetValue() const override
{ {
@ -438,7 +438,7 @@ protected:
class LiteralReal : public LiteralExpression class LiteralReal : public LiteralExpression
{ {
public: public:
LiteralReal(ControlState value) : m_value(value) {} explicit LiteralReal(ControlState value) : m_value(value) {}
ControlState GetValue() const override { return m_value; } ControlState GetValue() const override { return m_value; }
@ -448,7 +448,7 @@ private:
const ControlState m_value{}; const ControlState m_value{};
}; };
static ParseResult MakeLiteralExpression(Token token) static ParseResult MakeLiteralExpression(const Token& token)
{ {
ControlState val{}; ControlState val{};
if (TryParse(token.data, &val)) if (TryParse(token.data, &val))
@ -460,7 +460,7 @@ static ParseResult MakeLiteralExpression(Token token)
class VariableExpression : public Expression class VariableExpression : public Expression
{ {
public: public:
VariableExpression(std::string name) : m_name(name) {} explicit VariableExpression(std::string name) : m_name(std::move(name)) {}
ControlState GetValue() const override { return m_variable_ptr ? *m_variable_ptr : 0; } ControlState GetValue() const override { return m_variable_ptr ? *m_variable_ptr : 0; }
@ -485,7 +485,7 @@ protected:
class HotkeyExpression : public Expression class HotkeyExpression : public Expression
{ {
public: public:
HotkeyExpression(std::vector<std::unique_ptr<ControlExpression>> inputs) explicit HotkeyExpression(std::vector<std::unique_ptr<ControlExpression>> inputs)
: m_modifiers(std::move(inputs)) : m_modifiers(std::move(inputs))
{ {
m_final_input = std::move(m_modifiers.back()); m_final_input = std::move(m_modifiers.back());
@ -600,7 +600,7 @@ private:
std::unique_ptr<Expression> m_rhs; std::unique_ptr<Expression> m_rhs;
}; };
std::shared_ptr<Device> ControlEnvironment::FindDevice(ControlQualifier qualifier) const std::shared_ptr<Device> ControlEnvironment::FindDevice(const ControlQualifier& qualifier) const
{ {
if (qualifier.has_device) if (qualifier.has_device)
return container.FindDevice(qualifier.device_qualifier); return container.FindDevice(qualifier.device_qualifier);
@ -608,7 +608,7 @@ std::shared_ptr<Device> ControlEnvironment::FindDevice(ControlQualifier qualifie
return container.FindDevice(default_device); return container.FindDevice(default_device);
} }
Device::Input* ControlEnvironment::FindInput(ControlQualifier qualifier) const Device::Input* ControlEnvironment::FindInput(const ControlQualifier& qualifier) const
{ {
const std::shared_ptr<Device> device = FindDevice(qualifier); const std::shared_ptr<Device> device = FindDevice(qualifier);
if (!device) if (!device)
@ -617,7 +617,7 @@ Device::Input* ControlEnvironment::FindInput(ControlQualifier qualifier) const
return device->FindInput(qualifier.control_name); return device->FindInput(qualifier.control_name);
} }
Device::Output* ControlEnvironment::FindOutput(ControlQualifier qualifier) const Device::Output* ControlEnvironment::FindOutput(const ControlQualifier& qualifier) const
{ {
const std::shared_ptr<Device> device = FindDevice(qualifier); const std::shared_ptr<Device> device = FindDevice(qualifier);
if (!device) if (!device)

View File

@ -150,9 +150,9 @@ public:
{ {
} }
std::shared_ptr<Core::Device> FindDevice(ControlQualifier qualifier) const; std::shared_ptr<Core::Device> FindDevice(const ControlQualifier& qualifier) const;
Core::Device::Input* FindInput(ControlQualifier qualifier) const; Core::Device::Input* FindInput(const ControlQualifier& qualifier) const;
Core::Device::Output* FindOutput(ControlQualifier qualifier) const; Core::Device::Output* FindOutput(const ControlQualifier& qualifier) const;
// Returns an existing variable by the specified name if already existing. Creates it otherwise. // Returns an existing variable by the specified name if already existing. Creates it otherwise.
std::shared_ptr<ControlState> GetVariablePtr(const std::string& name); std::shared_ptr<ControlState> GetVariablePtr(const std::string& name);