Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
More improvements to the binary expression handling
Browse files Browse the repository at this point in the history
- Avoid extra copy in binary expressions when the lhs is a constant expression since it can't be modified.
  • Loading branch information
MerlinVR committed Apr 10, 2020
1 parent 68009c7 commit d502c4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Assets/UdonSharp/Editor/UdonSharpASTVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,7 @@ public override void VisitBinaryExpression(BinaryExpressionSyntax node)
{
Visit(node.Left);

if (lhsCapture.DoesReturnIntermediateSymbol())
if (lhsCapture.DoesReturnIntermediateSymbol() || lhsCapture.IsConstExpression())
{
lhsValue = lhsCapture.ExecuteGet();
}
Expand Down
9 changes: 9 additions & 0 deletions Assets/UdonSharp/Editor/UdonSharpExpressionCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d502c4a

Please sign in to comment.