Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use temporary variable to evaluate property value only once
  • Loading branch information
etemi authored Jun 16, 2023
commit 0ea98011c3e2a0878a2ffc47279ab69d1c128841
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,18 @@ private void GenerateFastPathFuncForObject(SourceWriter writer, ContextGeneratio
? $"(({propertyGenSpec.DeclaringType.FullyQualifiedName}){ValueVarName})"
: ValueVarName;

string propValueExpr = $"{objectExpr}.{propertyGenSpec.NameSpecifiedInSourceCode}";
string propValueExpr;
if (defaultCheckType != DefaultCheckType.None)
{
// Use temporary variable to evaluate property value only once
string localVariableName = $"__value_{propertyGenSpec.NameSpecifiedInSourceCode}";
writer.WriteLine($"{propertyGenSpec.PropertyType.FullyQualifiedName} {localVariableName} = {objectExpr}.{propertyGenSpec.NameSpecifiedInSourceCode};");
propValueExpr = localVariableName;
}
else
{
propValueExpr = $"{objectExpr}.{propertyGenSpec.NameSpecifiedInSourceCode}";
}

switch (defaultCheckType)
{
Expand Down