Skip to content

Commit

Permalink
Merge pull request #11466 from Youssef1313/fix-leak
Browse files Browse the repository at this point in the history
perf: Avoid holding into symbols
  • Loading branch information
MartinZikmund committed Mar 4, 2023
2 parents 77e2a01 + 94cbbfe commit a06ffd9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#nullable enable

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;

namespace Uno.UI.SourceGenerators.XamlGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
{
internal record GenerationRunFileInfo(GenerationRunInfo RunInfo, string FileId)
{
private Dictionary<INamedTypeSymbol, int> _appliedTypes = new Dictionary<INamedTypeSymbol, int>();
private Dictionary<string, int> _appliedTypes = new Dictionary<string, int>();

internal string? ComponentCode { get; set; }

internal IReadOnlyDictionary<INamedTypeSymbol, int> AppliedTypes => _appliedTypes;
internal IReadOnlyDictionary<string, int> AppliedTypes => _appliedTypes;

internal void SetAppliedTypes(Dictionary<INamedTypeSymbol, int> appliedTypes)
internal void SetAppliedTypes(Dictionary<string, int> appliedTypes)
{
foreach (var type in appliedTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ internal partial class XamlFileGenerator
/// <summary>
/// Information about types used in .Apply() scenarios
/// </summary>
private readonly Dictionary<INamedTypeSymbol, int> _xamlAppliedTypes = new Dictionary<INamedTypeSymbol, int>();
/// <remarks>
/// The key of the dictionary is the globalized fully qualified name.
/// </remarks>
private readonly Dictionary<string, int> _xamlAppliedTypes = new();

private readonly List<INamedTypeSymbol> _xamlConversionTypes;

Expand Down Expand Up @@ -602,11 +605,11 @@ private void BuildXamlApplyBlocks(IndentedStringBuilder writer)
{
foreach (var typeInfo in _xamlAppliedTypes)
{
writer.AppendLineIndented($"public delegate void XamlApplyHandler{typeInfo.Value}({GetGlobalizedTypeName(typeInfo.Key.ToString())} instance);");
writer.AppendLineIndented($"public delegate void XamlApplyHandler{typeInfo.Value}({typeInfo.Key} instance);");

writer.AppendLineIndented($"[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]");
using (writer.BlockInvariant(
$"public static {GetGlobalizedTypeName(typeInfo.Key.ToString())} {_fileUniqueId}_XamlApply(this {GetGlobalizedTypeName(typeInfo.Key.ToString())} instance, XamlApplyHandler{typeInfo.Value} handler)"
$"public static {typeInfo.Key} {_fileUniqueId}_XamlApply(this {typeInfo.Key} instance, XamlApplyHandler{typeInfo.Value} handler)"
))
{
writer.AppendLineIndented($"handler(instance);");
Expand Down Expand Up @@ -4095,10 +4098,11 @@ private XamlLazyApplyBlockIIndentedStringBuilder CreateApplyBlock(IIndentedStrin

if (appliedType != null)
{
if (!_xamlAppliedTypes.TryGetValue(appliedType, out var appliedTypeIndex))
var globalizedFullyQualifiedAppliedType = GetGlobalizedTypeName(appliedType.ToString());
if (!_xamlAppliedTypes.TryGetValue(globalizedFullyQualifiedAppliedType, out var appliedTypeIndex))
{
appliedTypeIndex = _xamlAppliedTypes.Count;
_xamlAppliedTypes.Add(appliedType, _xamlAppliedTypes.Count);
_xamlAppliedTypes.Add(globalizedFullyQualifiedAppliedType, _xamlAppliedTypes.Count);
}

if (_isHotReloadEnabled)
Expand Down

0 comments on commit a06ffd9

Please sign in to comment.