From 814fd165af56289401124989806201a4d110bc08 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 22 Nov 2019 15:07:16 -0500 Subject: [PATCH] InputCommon/FunctionExpression: Use Yoda conditions, we do not The general convention in the codebase is to compare the non-constant value/string with the constant value/string, not the other way around. --- .../ControlReference/FunctionExpression.cpp | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Source/Core/InputCommon/ControlReference/FunctionExpression.cpp b/Source/Core/InputCommon/ControlReference/FunctionExpression.cpp index 6463a85101..75f78526e6 100644 --- a/Source/Core/InputCommon/ControlReference/FunctionExpression.cpp +++ b/Source/Core/InputCommon/ControlReference/FunctionExpression.cpp @@ -23,7 +23,7 @@ private: ValidateArguments(const std::vector>& args) override { // Optional 2nd argument for clearing state: - if (1 == args.size() || 2 == args.size()) + if (args.size() == 1 || args.size() == 2) return ArgumentsAreValid{}; else return ExpectedArguments{"toggle_state_input, [clear_state_input]"}; @@ -62,7 +62,7 @@ private: ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (1 == args.size()) + if (args.size() == 1) return ArgumentsAreValid{}; else return ExpectedArguments{"expression"}; @@ -79,7 +79,7 @@ private: ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (1 == args.size()) + if (args.size() == 1) return ArgumentsAreValid{}; else return ExpectedArguments{"expression"}; @@ -95,7 +95,7 @@ private: ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (1 == args.size()) + if (args.size() == 1) return ArgumentsAreValid{}; else return ExpectedArguments{"seconds"}; @@ -138,7 +138,7 @@ private: ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (3 == args.size()) + if (args.size() == 3) return ArgumentsAreValid{}; else return ExpectedArguments{"condition, true_expression, false_expression"}; @@ -158,7 +158,7 @@ private: ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (1 == args.size()) + if (args.size() == 1) return ArgumentsAreValid{}; else return ExpectedArguments{"expression"}; @@ -177,7 +177,7 @@ class DeadzoneExpression : public FunctionExpression ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (2 == args.size()) + if (args.size() == 2) return ArgumentsAreValid{}; else return ExpectedArguments{"input, amount"}; @@ -198,7 +198,7 @@ class SmoothExpression : public FunctionExpression ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (2 == args.size() || 3 == args.size()) + if (args.size() == 2 || args.size() == 3) return ArgumentsAreValid{}; else return ExpectedArguments{"input, seconds_up, seconds_down = seconds_up"}; @@ -213,7 +213,7 @@ class SmoothExpression : public FunctionExpression const ControlState desired_value = GetArg(0).GetValue(); const ControlState smooth_up = GetArg(1).GetValue(); - const ControlState smooth_down = (3 == GetArgCount() ? GetArg(2).GetValue() : smooth_up); + const ControlState smooth_down = GetArgCount() == 3 ? GetArg(2).GetValue() : smooth_up; const ControlState smooth = (desired_value < m_value) ? smooth_down : smooth_up; const ControlState max_move = std::chrono::duration_cast(elapsed).count() / smooth; @@ -242,7 +242,7 @@ class HoldExpression : public FunctionExpression ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (2 == args.size()) + if (args.size() == 2) return ArgumentsAreValid{}; else return ExpectedArguments{"input, seconds"}; @@ -281,7 +281,7 @@ class TapExpression : public FunctionExpression ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (2 == args.size() || 3 == args.size()) + if (args.size() == 2 || args.size() == 3) return ArgumentsAreValid{}; else return ExpectedArguments{"input, seconds, taps = 2"}; @@ -298,7 +298,7 @@ class TapExpression : public FunctionExpression const bool is_time_up = elapsed > seconds; - const u32 desired_taps = (3 == GetArgCount()) ? u32(GetArg(2).GetValue() + 0.5) : 2; + const u32 desired_taps = GetArgCount() == 3 ? u32(GetArg(2).GetValue() + 0.5) : 2; if (input < CONDITION_THRESHOLD) { @@ -400,7 +400,7 @@ class PulseExpression : public FunctionExpression ArgumentValidation ValidateArguments(const std::vector>& args) override { - if (2 == args.size()) + if (args.size() == 2) return ArgumentsAreValid{}; else return ExpectedArguments{"input, seconds"}; @@ -449,29 +449,29 @@ private: std::unique_ptr MakeFunctionExpression(std::string_view name) { - if ("not" == name) + if (name == "not") return std::make_unique(); - if ("if" == name) + if (name == "if") return std::make_unique(); - if ("sin" == name) + if (name == "sin") return std::make_unique(); - if ("timer" == name) + if (name == "timer") return std::make_unique(); - if ("toggle" == name) + if (name == "toggle") return std::make_unique(); - if ("minus" == name) + if (name == "minus") return std::make_unique(); - if ("deadzone" == name) + if (name == "deadzone") return std::make_unique(); - if ("smooth" == name) + if (name == "smooth") return std::make_unique(); - if ("hold" == name) + if (name == "hold") return std::make_unique(); - if ("tap" == name) + if (name == "tap") return std::make_unique(); - if ("relative" == name) + if (name == "relative") return std::make_unique(); - if ("pulse" == name) + if (name == "pulse") return std::make_unique(); return nullptr;