Skip to content

Avoid boxing booleans during tracing and when setting bool? properties #10884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Specialized;
using MS.Internal;
using MS.Internal.KnownBoxes;

namespace System.Windows
{
Expand Down Expand Up @@ -135,7 +136,7 @@ public bool Handled
{
TraceRoutedEvent.TraceActivityItem(
TraceRoutedEvent.HandleEvent,
value,
BooleanBoxes.Box(value),
RoutedEvent.OwnerType.Name,
RoutedEvent.Name,
this );
Expand Down Expand Up @@ -289,7 +290,6 @@ protected virtual void InvokeEventHandler(Delegate genericHandler, object generi
}
else
{
// Restricted Action - reflection permission required
genericHandler.DynamicInvoke(new object[] {genericTarget, this});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ private static void ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args
args.RoutedEvent,
sender,
args,
args.Handled );
BooleanBoxes.Box(args.Handled));
}

try
Expand Down Expand Up @@ -2275,7 +2275,7 @@ private static void ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args
args.RoutedEvent,
sender,
args,
args.Handled );
BooleanBoxes.Box(args.Handled));
}
}

Expand All @@ -2299,7 +2299,7 @@ internal static void RaiseEventImpl(DependencyObject sender, RoutedEventArgs arg
args.RoutedEvent,
sender,
args,
args.Handled );
BooleanBoxes.Box(args.Handled));
}

try
Expand All @@ -2325,7 +2325,7 @@ internal static void RaiseEventImpl(DependencyObject sender, RoutedEventArgs arg
args.RoutedEvent,
sender,
args,
args.Handled );
BooleanBoxes.Box(args.Handled));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Xml;

using MS.Internal;
using MS.Internal.KnownBoxes;

namespace System.Windows.Controls
{
Expand Down Expand Up @@ -555,7 +556,7 @@ private static Style AccessKeyStyle
Trigger trigger = new Trigger
{
Property = KeyboardNavigation.ShowKeyboardCuesProperty,
Value = true
Value = BooleanBoxes.TrueBox
};
trigger.Setters.Add(new Setter(TextDecorationsProperty, System.Windows.TextDecorations.Underline));
accessKeyStyle.Triggers.Add(trigger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,9 @@ private static object CoerceIsSelectionBoxHighlighted(object o, object value)
{
ComboBox comboBox = (ComboBox)o;
ComboBoxItem highlightedElement;
return (!comboBox.IsDropDownOpen && comboBox.IsKeyboardFocusWithin) ||
((highlightedElement = comboBox.HighlightedElement) != null && highlightedElement.Content == comboBox._clonedElement);

return BooleanBoxes.Box((!comboBox.IsDropDownOpen && comboBox.IsKeyboardFocusWithin) ||
((highlightedElement = comboBox.HighlightedElement) != null && highlightedElement.Content == comboBox._clonedElement));
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows.Data;
using System.Windows.Input;
using MS.Internal;
using MS.Internal.KnownBoxes;

namespace System.Windows.Controls
{
Expand Down Expand Up @@ -1271,19 +1272,8 @@ private static object OnCoerceIsFrozen(DependencyObject d, object baseValue)
{
DataGridColumn column = (DataGridColumn)d;
DataGrid dataGrid = column.DataGridOwner;
if (dataGrid != null)
{
if (column.DisplayIndex < dataGrid.FrozenColumnCount)
{
return true;
}
else
{
return false;
}
}

return baseValue;
return dataGrid is null ? baseValue : BooleanBoxes.Box(column.DisplayIndex < dataGrid.FrozenColumnCount);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// that manages layout of containers for an ItemsControl.
//

using MS.Internal.KnownBoxes;

namespace System.Windows.Controls
{
/// <summary>
Expand Down Expand Up @@ -124,7 +126,7 @@ internal override void ProcessTemplateBeforeSeal()
if (!typeof(Panel).IsAssignableFrom(root.Type))
throw new InvalidOperationException(SR.Format(SR.ItemsPanelNotAPanel, root.Type));

root.SetValue(Panel.IsItemsHostProperty, true);
root.SetValue(Panel.IsItemsHostProperty, BooleanBoxes.TrueBox);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Specialized;
using System.Windows.Media;
using System.Windows.Controls.Primitives; // IItemContainerGenerator
using MS.Internal.KnownBoxes;

namespace System.Windows.Controls
{
Expand Down Expand Up @@ -333,7 +334,8 @@ private static bool ValidateCacheSizeBeforeOrAfterViewport(object value)
private static object CoerceIsVirtualizingWhenGrouping(DependencyObject d, object baseValue)
{
bool isVirtualizing = GetIsVirtualizing(d);
return isVirtualizing && (bool)baseValue;

return BooleanBoxes.Box(isVirtualizing && (bool)baseValue);
}

internal static void OnVirtualizationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
using System.Collections; // IEnumerable
using System.Collections.ObjectModel; // ObservableCollection<T>
using System.Collections.Specialized; // NotifyCollectionChanged*
using System.Globalization; // CultureInfo
using System.ComponentModel; // ICollectionView
using System.Globalization; // CultureInfo
using System.Windows.Markup; // XmlLanguage
using MS.Internal; // Invariant.Assert
using MS.Internal.Data; // DataBindEngine
using MS.Internal.KnownBoxes;

namespace System.Windows.Data
{
Expand Down Expand Up @@ -329,7 +330,7 @@ public static readonly DependencyProperty IsLiveSortingProperty
public bool? IsLiveSorting
{
get { return (bool?)GetValue(IsLiveSortingProperty); }
private set { SetValue(IsLiveSortingPropertyKey, value); }
private set { SetValue(IsLiveSortingPropertyKey, BooleanBoxes.Box(value)); }
}

///<summary>
Expand Down Expand Up @@ -452,7 +453,7 @@ public static readonly DependencyProperty IsLiveFilteringProperty
public bool? IsLiveFiltering
{
get { return (bool?)GetValue(IsLiveFilteringProperty); }
private set { SetValue(IsLiveFilteringPropertyKey, value); }
private set { SetValue(IsLiveFilteringPropertyKey, BooleanBoxes.Box(value)); }
}

///<summary>
Expand Down Expand Up @@ -573,7 +574,7 @@ public static readonly DependencyProperty IsLiveGroupingProperty
public bool? IsLiveGrouping
{
get { return (bool?)GetValue(IsLiveGroupingProperty); }
private set { SetValue(IsLiveGroupingPropertyKey, value); }
private set { SetValue(IsLiveGroupingPropertyKey, BooleanBoxes.Box(value)); }
}

///<summary>
Expand Down