Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
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
9 changes: 7 additions & 2 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ jobs:
- name: Display dotnet info
run: dotnet --info

- name: Build Benchmarks
run: |
dotnet build ${{ env.PathToCommunityToolkitAnalyzersBenchmarksCsproj }} -c Release
dotnet build ${{ env.PathToCommunityToolkitSourceGeneratorsBenchmarksCsproj }} -c Release

- name: Run Analyzer Benchmarks
run: dotnet run --project ${{ env.PathToCommunityToolkitAnalyzersBenchmarksCsproj }} -c Release -- -a "${{ runner.temp }}"
run: dotnet run --project ${{ env.PathToCommunityToolkitAnalyzersBenchmarksCsproj }} -c Release --no-build -- -a "${{ runner.temp }}"

- name: Run Source Generator Benchmarks
run: dotnet run --project ${{ env.PathToCommunityToolkitSourceGeneratorsBenchmarksCsproj }} -c Release -- -a "${{ runner.temp }}"
run: dotnet run --project ${{ env.PathToCommunityToolkitSourceGeneratorsBenchmarksCsproj }} -c Release --no-build -- -a "${{ runner.temp }}"

- name: Publish Benchmarks
uses: actions/upload-artifact@v7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,22 +610,36 @@ public partial class {{defaultTestClassName}}

file static class __{{defaultTestClassName}}BindablePropertyInitHelpers
{
public static volatile bool IsInitializingText = false;
[global::System.ThreadStatic]
public static bool IsInitializingText;
public static object CreateDefaultText(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingText = true;
var defaultValue = ((TestView)bindable).Text;
IsInitializingText = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).Text;
return defaultValue;
}
finally
{
IsInitializingText = false;
}
}

public static volatile bool IsInitializingCustomDuration = false;
[global::System.ThreadStatic]
public static bool IsInitializingCustomDuration;
public static object CreateDefaultCustomDuration(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingCustomDuration = true;
var defaultValue = ((TestView)bindable).CustomDuration;
IsInitializingCustomDuration = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).CustomDuration;
return defaultValue;
}
finally
{
IsInitializingCustomDuration = false;
}
}
}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@ public partial class {{defaultTestClassName}}

file static class __{{defaultTestClassName}}BindablePropertyInitHelpers
{
public static volatile bool IsInitializingInvoiceStatus = false;
[global::System.ThreadStatic]
public static bool IsInitializingInvoiceStatus;
public static object CreateDefaultInvoiceStatus(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingInvoiceStatus = true;
var defaultValue = ((TestView)bindable).InvoiceStatus;
IsInitializingInvoiceStatus = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).InvoiceStatus;
return defaultValue;
}
finally
{
IsInitializingInvoiceStatus = false;
}
}
}
""";
Expand Down Expand Up @@ -160,13 +167,20 @@ public partial class {{defaultTestClassName}}

file static class __{{defaultTestClassName}}BindablePropertyInitHelpers
{
public static volatile bool IsInitializingInvoiceStatus = false;
[global::System.ThreadStatic]
public static bool IsInitializingInvoiceStatus;
public static object CreateDefaultInvoiceStatus(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingInvoiceStatus = true;
var defaultValue = ((TestView)bindable).InvoiceStatus;
IsInitializingInvoiceStatus = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).InvoiceStatus;
return defaultValue;
}
finally
{
IsInitializingInvoiceStatus = false;
}
}
}
""";
Expand Down Expand Up @@ -516,67 +530,116 @@ public partial class {{defaultTestClassName}}

file static class __{{defaultTestClassName}}BindablePropertyInitHelpers
{
public static volatile bool IsInitializingIsEnabled = false;
[global::System.ThreadStatic]
public static bool IsInitializingIsEnabled;
public static object CreateDefaultIsEnabled(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingIsEnabled = true;
var defaultValue = ((TestView)bindable).IsEnabled;
IsInitializingIsEnabled = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).IsEnabled;
return defaultValue;
}
finally
{
IsInitializingIsEnabled = false;
}
}

public static volatile bool IsInitializingPi = false;
[global::System.ThreadStatic]
public static bool IsInitializingPi;
public static object CreateDefaultPi(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingPi = true;
var defaultValue = ((TestView)bindable).Pi;
IsInitializingPi = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).Pi;
return defaultValue;
}
finally
{
IsInitializingPi = false;
}
}

public static volatile bool IsInitializingLetter = false;
[global::System.ThreadStatic]
public static bool IsInitializingLetter;
public static object CreateDefaultLetter(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingLetter = true;
var defaultValue = ((TestView)bindable).Letter;
IsInitializingLetter = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).Letter;
return defaultValue;
}
finally
{
IsInitializingLetter = false;
}
}

public static volatile bool IsInitializingTimeSpent = false;
[global::System.ThreadStatic]
public static bool IsInitializingTimeSpent;
public static object CreateDefaultTimeSpent(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingTimeSpent = true;
var defaultValue = ((TestView)bindable).TimeSpent;
IsInitializingTimeSpent = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).TimeSpent;
return defaultValue;
}
finally
{
IsInitializingTimeSpent = false;
}
}

public static volatile bool IsInitializingDoubleEpsilon = false;
[global::System.ThreadStatic]
public static bool IsInitializingDoubleEpsilon;
public static object CreateDefaultDoubleEpsilon(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingDoubleEpsilon = true;
var defaultValue = ((TestView)bindable).DoubleEpsilon;
IsInitializingDoubleEpsilon = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).DoubleEpsilon;
return defaultValue;
}
finally
{
IsInitializingDoubleEpsilon = false;
}
}

public static volatile bool IsInitializingSingleEpsilon = false;
[global::System.ThreadStatic]
public static bool IsInitializingSingleEpsilon;
public static object CreateDefaultSingleEpsilon(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingSingleEpsilon = true;
var defaultValue = ((TestView)bindable).SingleEpsilon;
IsInitializingSingleEpsilon = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).SingleEpsilon;
return defaultValue;
}
finally
{
IsInitializingSingleEpsilon = false;
}
}

public static volatile bool IsInitializingCurrentTime = false;
[global::System.ThreadStatic]
public static bool IsInitializingCurrentTime;
public static object CreateDefaultCurrentTime(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingCurrentTime = true;
var defaultValue = ((TestView)bindable).CurrentTime;
IsInitializingCurrentTime = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).CurrentTime;
return defaultValue;
}
finally
{
IsInitializingCurrentTime = false;
}
}
}
""";
Expand Down Expand Up @@ -690,31 +753,52 @@ public partial class {{defaultTestClassName}}

file static class __{{defaultTestClassName}}BindablePropertyInitHelpers
{
public static volatile bool IsInitializingText = false;
[global::System.ThreadStatic]
public static bool IsInitializingText;
public static object CreateDefaultText(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingText = true;
var defaultValue = ((TestView)bindable).Text;
IsInitializingText = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).Text;
return defaultValue;
}
finally
{
IsInitializingText = false;
}
}

public static volatile bool IsInitializingTime = false;
[global::System.ThreadStatic]
public static bool IsInitializingTime;
public static object CreateDefaultTime(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingTime = true;
var defaultValue = ((TestView)bindable).Time;
IsInitializingTime = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).Time;
return defaultValue;
}
finally
{
IsInitializingTime = false;
}
}

public static volatile bool IsInitializingCustomDuration = false;
[global::System.ThreadStatic]
public static bool IsInitializingCustomDuration;
public static object CreateDefaultCustomDuration(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingCustomDuration = true;
var defaultValue = ((TestView)bindable).CustomDuration;
IsInitializingCustomDuration = false;
return defaultValue;
try
{
var defaultValue = ((TestView)bindable).CustomDuration;
return defaultValue;
}
finally
{
IsInitializingCustomDuration = false;
}
}
}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,20 @@ public partial class {{defaultTestClassName}}<T, U>
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private static class __{{defaultTestClassName}}BindablePropertyInitHelpers
{
public static volatile bool IsInitializingValue = false;
[global::System.ThreadStatic]
public static bool IsInitializingValue;
public static object CreateDefaultValue(global::Microsoft.Maui.Controls.BindableObject bindable)
{
IsInitializingValue = true;
var defaultValue = (({{defaultTestClassName}}<T, U>)bindable).Value;
IsInitializingValue = false;
return defaultValue;
try
{
var defaultValue = (({{defaultTestClassName}}<T, U>)bindable).Value;
return defaultValue;
}
finally
{
IsInitializingValue = false;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,16 @@ static string GetFormattedReturnType(ITypeSymbol typeSymbol)
/// <param name="info">Property model.</param>
static void AppendHelperInitializingField(StringBuilder fileStaticClassStringBuilder, in BindablePropertyModel info)
{
// Make the flag public static so it can be referenced from the generated partial class in the same file.
fileStaticClassStringBuilder.Append("public static volatile bool ")
// Use [ThreadStatic] so each thread has its own flag, preventing cross-thread
// interference when multiple instances resolve default values concurrently.
fileStaticClassStringBuilder.Append("[global::System.ThreadStatic]\npublic static bool ")
.Append(info.InitializingPropertyName)
.Append(" = false;\n");
.Append(";\n");
}

/// <summary>
/// Appends a default value creator method into the file-static helper class.
/// The method sets the static initializing flag, reads the property's initializer value by casting the bindable
/// The method sets the thread-static initializing flag, reads the property's initializer value by casting the bindable
/// to the declaring type, then clears the flag and returns the value.
/// </summary>
/// <param name="fileStaticClassStringBuilder">Helper StringBuilder used to collect helper members.</param>
Expand All @@ -621,14 +622,17 @@ static void AppendHelperDefaultValueMethod(StringBuilder fileStaticClassStringBu
.Append("{\n")
.Append(info.InitializingPropertyName)
.Append(" = true;\n")
Comment thread
TheCodeTraveler marked this conversation as resolved.
.Append("try\n{\n")
.Append("var defaultValue = ((")
.Append(fullDeclaringType)
.Append(")bindable).")
.Append(sanitizedPropertyName)
.Append(";\n")
.Append("return defaultValue;\n")
.Append("}\nfinally\n{\n")
.Append(info.InitializingPropertyName)
.Append(" = false;\n")
.Append("return defaultValue;\n")
.Append("}\n")
.Append("}\n\n");
}
}
Loading
Loading