Skip to content

Commit

Permalink
perf: Use StringBuilderBasedSourceText in `DependencyObjectAvailabi…
Browse files Browse the repository at this point in the history
…lityGenerator`
  • Loading branch information
Youssef1313 committed Apr 22, 2023
1 parent bdd49d9 commit 31701d7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#nullable enable

using Uno.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.CodeAnalysis;
using Uno.Extensions;
using Uno.Roslyn;
using Uno.UI.SourceGenerators.XamlGenerator;
using Uno.UI.SourceGenerators.Helpers;
using System.Xml;
using Uno.UI.SourceGenerators.Utils;
using Uno.UI.SourceGenerators.XamlGenerator;

#if NETFRAMEWORK
using Uno.SourceGeneration;
Expand All @@ -32,7 +33,7 @@ public void Execute(GeneratorExecutionContext context)
new Generator().Generate(context);
}

class Generator
private sealed class Generator
{
private string? _defaultNamespace;
private string? _projectFullPath;
Expand Down Expand Up @@ -98,19 +99,6 @@ from type in module.GlobalNamespace.GetNamespaceTypes()

context.AddSource("DependencyObjectAvailability", GenerateTypeProviders(propertyNames));

#if DEBUG
context.AddSource("DependencyObjectAvailability_Debug",
$"""
/*
_assemblyName:{_assemblyName}
_dependencyObjectSymbol:{_dependencyObjectSymbol}
modules: {string.Join(", ", modules)}
_additionalLinkerHintAttributeSymbol: {_additionalLinkerHintAttributeSymbol}
additionalLinkerHintSymbols: {string.Join(",", additionalLinkerHintSymbols)}
*/
""");
#endif

GenerateLinkerSubstitutionDefinition(propertyNames);
}
}
Expand Down Expand Up @@ -234,18 +222,17 @@ private void GenerateLinkerSubstitutionDefinition(string[] propertyNames)
doc.Save(fileName);
}

private string GenerateTypeProviders(string[] propertyNames)
private StringBuilderBasedSourceText GenerateTypeProviders(string[] propertyNames)
{
var writer = new IndentedStringBuilder();

writer.AppendLineIndented("// <auto-generated>");
writer.AppendLineIndented("// *****************************************************************************");
writer.AppendLineIndented("// This file has been generated by Uno.UI (BindableTypeProvidersSourceGenerator)");
writer.AppendLineIndented("// This file has been generated by Uno.UI (DependencyObjectAvailabilityGenerator)");
writer.AppendLineIndented("// *****************************************************************************");
writer.AppendLineIndented("// </auto-generated>");
writer.AppendLine();
writer.AppendLineIndented("#pragma warning disable 618 // Ignore obsolete members warnings");
writer.AppendLineIndented("#pragma warning disable 1591 // Ignore missing XML comment warnings");

writer.AppendLineIndented($"// _intermediatePath: {_intermediatePath}");
writer.AppendLineIndented($"// _intermediateOutputPath: {_intermediateOutputPath}");
Expand All @@ -261,7 +248,7 @@ private string GenerateTypeProviders(string[] propertyNames)
}
}

return writer.ToString();
return new StringBuilderBasedSourceText(writer.Builder);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text;
using Microsoft.CodeAnalysis.Text;

namespace Uno.UI.SourceGenerators.XamlGenerator.Utils;
namespace Uno.UI.SourceGenerators.Utils;

/// <summary>
/// A SourceText implementation that is more performant for cases when we already have a StringBuilder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using System.Collections.Concurrent;
using System.Collections.Immutable;
using Uno.UI.SourceGenerators.Helpers;
using Uno.UI.SourceGenerators.XamlGenerator.Utils;
using Uno.UI.SourceGenerators.Utils;

#if NETFRAMEWORK
using Microsoft.Build.Execution;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#nullable enable

using Uno.Extensions;
using Uno.MsBuildTasks.Utils;
using Uno.UI.SourceGenerators.XamlGenerator.Utils;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis;
using Uno.Roslyn;
using Uno.UI.SourceGenerators.XamlGenerator.XamlRedirection;
using System.Runtime.CompilerServices;
using Uno.UI.Xaml;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using Uno.Disposables;
using Uno.Extensions;
using Uno.MsBuildTasks.Utils;
using Uno.Roslyn;
using Uno.UI.SourceGenerators.BindableTypeProviders;
using Microsoft.CodeAnalysis.CSharp;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Uno.UI.SourceGenerators.Helpers;
using System.Collections.Immutable;
using System.Text;
using Microsoft.CodeAnalysis.Text;

using Uno.UI.SourceGenerators.Utils;
using Uno.UI.SourceGenerators.XamlGenerator.Utils;
using Uno.UI.SourceGenerators.XamlGenerator.XamlRedirection;
using Uno.UI.Xaml;

#if NETFRAMEWORK
using Uno.SourceGeneration;
Expand Down

0 comments on commit 31701d7

Please sign in to comment.