From d502c4a58c3ac4e49f2412e13f26fe69432c6ffb Mon Sep 17 00:00:00 2001 From: Merlin <36685500+Merlin-san@users.noreply.github.com> Date: Thu, 9 Apr 2020 17:05:23 -0700 Subject: [PATCH] More improvements to the binary expression handling - Avoid extra copy in binary expressions when the lhs is a constant expression since it can't be modified. --- Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs | 2 +- Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs b/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs index 022ad86c..fdfb7f3d 100644 --- a/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs +++ b/Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs @@ -1574,7 +1574,7 @@ public override void VisitBinaryExpression(BinaryExpressionSyntax node) { Visit(node.Left); - if (lhsCapture.DoesReturnIntermediateSymbol()) + if (lhsCapture.DoesReturnIntermediateSymbol() || lhsCapture.IsConstExpression()) { lhsValue = lhsCapture.ExecuteGet(); } diff --git a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs index 0b4b1b6c..68594186 100644 --- a/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs +++ b/Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs @@ -1419,6 +1419,15 @@ public bool DoesReturnIntermediateSymbol() return !IsLocalSymbol(); } + public bool IsConstExpression() + { + // Only basic handling for local symbols for now since we can directly reference them + if (IsLocalSymbol() && ExecuteGet().declarationType.HasFlag(SymbolDeclTypeFlags.Constant)) + return true; + + return false; + } + public bool ResolveAccessToken(string accessToken) { bool resolvedToken = false;