From 8eb1398f8d90fb2813f438b9fffac716b6ec51d2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:17:32 -0400 Subject: video_core/{ast, expr}: Use std::move where applicable Avoids unnecessary atomic reference count increments and decrements. --- src/video_core/shader/expr.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/video_core/shader/expr.cpp') 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 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#pragma once - #include #include #include "video_core/shader/expr.h" namespace VideoCommon::Shader { +namespace { +bool ExprIsBoolean(const Expr& expr) { + return std::holds_alternative(*expr); +} + +bool ExprBooleanGet(const Expr& expr) { + return std::get_if(expr.get())->value; +} +} // Anonymous namespace bool ExprAnd::operator==(const ExprAnd& b) const { return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); @@ -23,19 +30,11 @@ bool ExprNot::operator==(const ExprNot& b) const { return (*operand1 == *b.operand1); } -bool ExprIsBoolean(Expr expr) { - return std::holds_alternative(*expr); -} - -bool ExprBooleanGet(Expr expr) { - return std::get_if(expr.get())->value; -} - Expr MakeExprNot(Expr first) { if (std::holds_alternative(*first)) { return std::get_if(first.get())->operand1; } - return MakeExpr(first); + return MakeExpr(std::move(first)); } Expr MakeExprAnd(Expr first, Expr second) { @@ -45,7 +44,7 @@ Expr MakeExprAnd(Expr first, Expr second) { if (ExprIsBoolean(second)) { return ExprBooleanGet(second) ? first : second; } - return MakeExpr(first, second); + return MakeExpr(std::move(first), std::move(second)); } Expr MakeExprOr(Expr first, Expr second) { @@ -55,14 +54,14 @@ Expr MakeExprOr(Expr first, Expr second) { if (ExprIsBoolean(second)) { return ExprBooleanGet(second) ? second : first; } - return MakeExpr(first, second); + return MakeExpr(std::move(first), std::move(second)); } -bool ExprAreEqual(Expr first, Expr second) { +bool ExprAreEqual(const Expr& first, const Expr& second) { return (*first) == (*second); } -bool ExprAreOpposite(Expr first, Expr second) { +bool ExprAreOpposite(const Expr& first, const Expr& second) { if (std::holds_alternative(*first)) { return ExprAreEqual(std::get_if(first.get())->operand1, second); } @@ -72,7 +71,7 @@ bool ExprAreOpposite(Expr first, Expr second) { return false; } -bool ExprIsTrue(Expr first) { +bool ExprIsTrue(const Expr& first) { if (ExprIsBoolean(first)) { return ExprBooleanGet(first); } -- cgit v1.2.3 From 50ad74558566af897db6d7a999101e40ee544108 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 5 Oct 2019 08:37:39 -0400 Subject: video_core/expr: Supply operator!= along with operator== Provides logical symmetry to the interface. --- src/video_core/shader/expr.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/video_core/shader/expr.cpp') diff --git a/src/video_core/shader/expr.cpp b/src/video_core/shader/expr.cpp index 39df7a927..2647865d4 100644 --- a/src/video_core/shader/expr.cpp +++ b/src/video_core/shader/expr.cpp @@ -22,12 +22,24 @@ bool ExprAnd::operator==(const ExprAnd& b) const { return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); } +bool ExprAnd::operator!=(const ExprAnd& b) const { + return !operator==(b); +} + bool ExprOr::operator==(const ExprOr& b) const { return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); } +bool ExprOr::operator!=(const ExprOr& b) const { + return !operator==(b); +} + bool ExprNot::operator==(const ExprNot& b) const { - return (*operand1 == *b.operand1); + return *operand1 == *b.operand1; +} + +bool ExprNot::operator!=(const ExprNot& b) const { + return !operator==(b); } Expr MakeExprNot(Expr first) { -- cgit v1.2.3