diff options
| author | 2019-10-05 08:17:32 -0400 | |
|---|---|---|
| committer | 2019-10-05 09:14:23 -0400 | |
| commit | 8eb1398f8d90fb2813f438b9fffac716b6ec51d2 (patch) | |
| tree | 39a270023b64af2dce85e3d4a13484c95243b2b3 /src/video_core/shader/expr.cpp | |
| parent | video_core/ast: Supply const accessors for data where applicable (diff) | |
| download | yuzu-8eb1398f8d90fb2813f438b9fffac716b6ec51d2.tar.gz yuzu-8eb1398f8d90fb2813f438b9fffac716b6ec51d2.tar.xz yuzu-8eb1398f8d90fb2813f438b9fffac716b6ec51d2.zip | |
video_core/{ast, expr}: Use std::move where applicable
Avoids unnecessary atomic reference count increments and decrements.
Diffstat (limited to 'src/video_core/shader/expr.cpp')
| -rw-r--r-- | src/video_core/shader/expr.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/video_core/shader/expr.cpp b/src/video_core/shader/expr.cpp index ca633ffb1..39df7a927 100644 --- a/src/video_core/shader/expr.cpp +++ b/src/video_core/shader/expr.cpp | |||
| @@ -2,14 +2,21 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | 5 | #include <memory> |
| 8 | #include <variant> | 6 | #include <variant> |
| 9 | 7 | ||
| 10 | #include "video_core/shader/expr.h" | 8 | #include "video_core/shader/expr.h" |
| 11 | 9 | ||
| 12 | namespace VideoCommon::Shader { | 10 | namespace VideoCommon::Shader { |
| 11 | namespace { | ||
| 12 | bool ExprIsBoolean(const Expr& expr) { | ||
| 13 | return std::holds_alternative<ExprBoolean>(*expr); | ||
| 14 | } | ||
| 15 | |||
| 16 | bool ExprBooleanGet(const Expr& expr) { | ||
| 17 | return std::get_if<ExprBoolean>(expr.get())->value; | ||
| 18 | } | ||
| 19 | } // Anonymous namespace | ||
| 13 | 20 | ||
| 14 | bool ExprAnd::operator==(const ExprAnd& b) const { | 21 | bool ExprAnd::operator==(const ExprAnd& b) const { |
| 15 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); | 22 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); |
| @@ -23,19 +30,11 @@ bool ExprNot::operator==(const ExprNot& b) const { | |||
| 23 | return (*operand1 == *b.operand1); | 30 | return (*operand1 == *b.operand1); |
| 24 | } | 31 | } |
| 25 | 32 | ||
| 26 | bool ExprIsBoolean(Expr expr) { | ||
| 27 | return std::holds_alternative<ExprBoolean>(*expr); | ||
| 28 | } | ||
| 29 | |||
| 30 | bool ExprBooleanGet(Expr expr) { | ||
| 31 | return std::get_if<ExprBoolean>(expr.get())->value; | ||
| 32 | } | ||
| 33 | |||
| 34 | Expr MakeExprNot(Expr first) { | 33 | Expr MakeExprNot(Expr first) { |
| 35 | if (std::holds_alternative<ExprNot>(*first)) { | 34 | if (std::holds_alternative<ExprNot>(*first)) { |
| 36 | return std::get_if<ExprNot>(first.get())->operand1; | 35 | return std::get_if<ExprNot>(first.get())->operand1; |
| 37 | } | 36 | } |
| 38 | return MakeExpr<ExprNot>(first); | 37 | return MakeExpr<ExprNot>(std::move(first)); |
| 39 | } | 38 | } |
| 40 | 39 | ||
| 41 | Expr MakeExprAnd(Expr first, Expr second) { | 40 | Expr MakeExprAnd(Expr first, Expr second) { |
| @@ -45,7 +44,7 @@ Expr MakeExprAnd(Expr first, Expr second) { | |||
| 45 | if (ExprIsBoolean(second)) { | 44 | if (ExprIsBoolean(second)) { |
| 46 | return ExprBooleanGet(second) ? first : second; | 45 | return ExprBooleanGet(second) ? first : second; |
| 47 | } | 46 | } |
| 48 | return MakeExpr<ExprAnd>(first, second); | 47 | return MakeExpr<ExprAnd>(std::move(first), std::move(second)); |
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | Expr MakeExprOr(Expr first, Expr second) { | 50 | Expr MakeExprOr(Expr first, Expr second) { |
| @@ -55,14 +54,14 @@ Expr MakeExprOr(Expr first, Expr second) { | |||
| 55 | if (ExprIsBoolean(second)) { | 54 | if (ExprIsBoolean(second)) { |
| 56 | return ExprBooleanGet(second) ? second : first; | 55 | return ExprBooleanGet(second) ? second : first; |
| 57 | } | 56 | } |
| 58 | return MakeExpr<ExprOr>(first, second); | 57 | return MakeExpr<ExprOr>(std::move(first), std::move(second)); |
| 59 | } | 58 | } |
| 60 | 59 | ||
| 61 | bool ExprAreEqual(Expr first, Expr second) { | 60 | bool ExprAreEqual(const Expr& first, const Expr& second) { |
| 62 | return (*first) == (*second); | 61 | return (*first) == (*second); |
| 63 | } | 62 | } |
| 64 | 63 | ||
| 65 | bool ExprAreOpposite(Expr first, Expr second) { | 64 | bool ExprAreOpposite(const Expr& first, const Expr& second) { |
| 66 | if (std::holds_alternative<ExprNot>(*first)) { | 65 | if (std::holds_alternative<ExprNot>(*first)) { |
| 67 | return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second); | 66 | return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second); |
| 68 | } | 67 | } |
| @@ -72,7 +71,7 @@ bool ExprAreOpposite(Expr first, Expr second) { | |||
| 72 | return false; | 71 | return false; |
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | bool ExprIsTrue(Expr first) { | 74 | bool ExprIsTrue(const Expr& first) { |
| 76 | if (ExprIsBoolean(first)) { | 75 | if (ExprIsBoolean(first)) { |
| 77 | return ExprBooleanGet(first); | 76 | return ExprBooleanGet(first); |
| 78 | } | 77 | } |