Skip to content

Commit

Permalink
perf: Avoid calling ToString twice on the same StringBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Feb 26, 2023
1 parent 772427d commit c77884d
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,16 @@ private string InnerGenerateFile()
{
BuildResourceDictionaryBackingClass(componentBuilder, topLevelControl);
BuildTopLevelResourceDictionary(componentBuilder, topLevelControl);
}

if (_useXamlReaderHotReload)
{
_generationRunFileInfo.SetAppliedTypes(_xamlAppliedTypes);
_generationRunFileInfo.ComponentCode = componentBuilder.ToString();
}
var componentCode = componentBuilder.ToString();
if (_useXamlReaderHotReload)
{
_generationRunFileInfo.SetAppliedTypes(_xamlAppliedTypes);
_generationRunFileInfo.ComponentCode = componentCode;
}

writer.AppendLineInvariantIndented("{0}", componentBuilder.ToString());
writer.AppendLineIndented(componentCode);
}
else
{
Expand All @@ -483,7 +484,7 @@ private string InnerGenerateFile()
{
var generationRunFileInfo = runFileInfo.GetRunFileInfo(_fileUniqueId);

writer.AppendLineInvariantIndented("{0}", generationRunFileInfo.ComponentCode);
writer.AppendLineIndented(generationRunFileInfo.ComponentCode);

foreach (var type in generationRunFileInfo.AppliedTypes)
{
Expand Down Expand Up @@ -533,15 +534,17 @@ private string InnerGenerateFile()
BuildComponentFields(componentBuilder);

BuildCompiledBindings(componentBuilder);
}

if (_useXamlReaderHotReload)
{
_generationRunFileInfo.SetAppliedTypes(_xamlAppliedTypes);
_generationRunFileInfo.ComponentCode = componentBuilder.ToString();
}
var componentCode = componentBuilder.ToString();

if (_useXamlReaderHotReload)
{
_generationRunFileInfo.SetAppliedTypes(_xamlAppliedTypes);
_generationRunFileInfo.ComponentCode = componentCode;
}

writer.AppendLineInvariantIndented("{0}", componentBuilder.ToString());
writer.AppendLineIndented(componentCode);
}
else
{
Expand Down

0 comments on commit c77884d

Please sign in to comment.