Browse Source

Simplify two if blocks into one (#14885)

* Fix typo in comments

* Simplify two if blocks into one

---------

Co-authored-by: Max Katz <maxkatz6@outlook.com>
pull/14905/head
Heku 2 years ago
committed by GitHub
parent
commit
9d8fd97365
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      src/Avalonia.Base/AvaloniaObject.cs
  2. 2
      src/Avalonia.Base/PropertyStore/EffectiveValue.cs
  3. 48
      src/Avalonia.Base/PropertyStore/ValueStore.cs

2
src/Avalonia.Base/AvaloniaObject.cs

@ -834,7 +834,7 @@ namespace Avalonia
} }
/// <summary> /// <summary>
/// Gets a description of an observable that van be used in logs. /// Gets a description of an observable that can be used in logs.
/// </summary> /// </summary>
/// <param name="o">The observable.</param> /// <param name="o">The observable.</param>
/// <returns>The description.</returns> /// <returns>The description.</returns>

2
src/Avalonia.Base/PropertyStore/EffectiveValue.cs

@ -89,7 +89,7 @@ namespace Avalonia.PropertyStore
/// Gets a value indicating whether the effective value represents the default value of the /// Gets a value indicating whether the effective value represents the default value of the
/// property and can be removed. /// property and can be removed.
/// </summary> /// </summary>
/// <returns>True if the effective value van be removed; otherwise false.</returns> /// <returns>True if the effective value can be removed; otherwise false.</returns>
public bool CanRemove() public bool CanRemove()
{ {
return Priority == BindingPriority.Unset && return Priority == BindingPriority.Unset &&

48
src/Avalonia.Base/PropertyStore/ValueStore.cs

@ -47,7 +47,8 @@ namespace Avalonia.PropertyStore
AvaloniaProperty property, AvaloniaProperty property,
UntypedBindingExpressionBase source) UntypedBindingExpressionBase source)
{ {
if (property.IsDirect) var priority = source.Priority;
if (priority == BindingPriority.LocalValue || property.IsDirect)
{ {
DisposeExistingLocalValueBinding(property); DisposeExistingLocalValueBinding(property);
_localValueBindings ??= new(); _localValueBindings ??= new();
@ -57,29 +58,16 @@ namespace Avalonia.PropertyStore
} }
else else
{ {
var priority = source.Priority; var effective = GetEffectiveValue(property);
var frame = GetOrCreateImmediateValueFrame(property, priority, out _);
if (priority == BindingPriority.LocalValue)
{
DisposeExistingLocalValueBinding(property);
_localValueBindings ??= new();
_localValueBindings[property.Id] = source;
source.AttachAndStart(this, Owner, property, priority);
return source;
}
else
{
var effective = GetEffectiveValue(property);
var frame = GetOrCreateImmediateValueFrame(property, priority, out _);
source.Attach(this, frame, Owner, property, priority); source.Attach(this, frame, Owner, property, priority);
frame.AddBinding(source); frame.AddBinding(source);
if (effective is null || priority <= effective.Priority) if (effective is null || priority <= effective.Priority)
source.Start(); source.Start();
return source; return source;
}
} }
} }
@ -607,7 +595,7 @@ namespace Avalonia.PropertyStore
/// <param name="oldValue">The old value of the property.</param> /// <param name="oldValue">The old value of the property.</param>
/// <param name="newValue">The new value of the property.</param> /// <param name="newValue">The new value of the property.</param>
public void OnAncestorInheritedValueChanged<T>( public void OnAncestorInheritedValueChanged<T>(
StyledProperty<T> property, StyledProperty<T> property,
T oldValue, T oldValue,
T newValue) T newValue)
{ {
@ -814,7 +802,7 @@ namespace Avalonia.PropertyStore
if (instance.IsDataValidationEnabled) if (instance.IsDataValidationEnabled)
Owner.OnUpdateDataValidation(property, BindingValueType.UnsetValue, null); Owner.OnUpdateDataValidation(property, BindingValueType.UnsetValue, null);
if (instance.Priority == BindingPriority.LocalValue) if (instance.Priority == BindingPriority.LocalValue)
{ {
if (_localValueBindings is not null && if (_localValueBindings is not null &&
@ -841,7 +829,7 @@ namespace Avalonia.PropertyStore
} }
private ImmediateValueFrame GetOrCreateImmediateValueFrame( private ImmediateValueFrame GetOrCreateImmediateValueFrame(
AvaloniaProperty property, AvaloniaProperty property,
BindingPriority priority, BindingPriority priority,
out int frameIndex) out int frameIndex)
{ {
@ -912,7 +900,7 @@ namespace Avalonia.PropertyStore
Debug.Assert(oldValue != newValue); Debug.Assert(oldValue != newValue);
Debug.Assert(oldValue is not null || newValue is not null); Debug.Assert(oldValue is not null || newValue is not null);
// If the value is set locally, propagaton ends here. // If the value is set locally, propagation ends here.
if (_effectiveValues.ContainsKey(property) == true) if (_effectiveValues.ContainsKey(property) == true)
return; return;
@ -967,7 +955,7 @@ namespace Avalonia.PropertyStore
// Try to get an entry from the frame for the property we're reevaluating. // Try to get an entry from the frame for the property we're reevaluating.
var foundEntry = frame.TryGetEntryIfActive(property, out var entry, out var activeChanged); var foundEntry = frame.TryGetEntryIfActive(property, out var entry, out var activeChanged);
// If the active state of the frame has changed since the last read, and // If the active state of the frame has changed since the last read, and
// the frame holds multiple values then we need to re-evaluate the // the frame holds multiple values then we need to re-evaluate the
// effective values of all properties. // effective values of all properties.
@ -982,7 +970,7 @@ namespace Avalonia.PropertyStore
// value for the property. Note that the check for entry.HasValue must be // value for the property. Note that the check for entry.HasValue must be
// evaluated last as it can cause bindings to be subscribed. // evaluated last as it can cause bindings to be subscribed.
if (foundEntry && if (foundEntry &&
HasHigherPriority(entry!, priority, current, changedValueEntry) && HasHigherPriority(entry!, priority, current, changedValueEntry) &&
entry!.HasValue()) entry!.HasValue())
{ {
if (current is not null) if (current is not null)
@ -1063,7 +1051,7 @@ namespace Avalonia.PropertyStore
var entry = frame.GetEntry(j); var entry = frame.GetEntry(j);
var property = entry.Property; var property = entry.Property;
_effectiveValues.TryGetValue(property, out var effectiveValue); _effectiveValues.TryGetValue(property, out var effectiveValue);
if (!HasHigherPriority(entry, priority, effectiveValue, changedValueEntry)) if (!HasHigherPriority(entry, priority, effectiveValue, changedValueEntry))
continue; continue;
@ -1119,7 +1107,7 @@ namespace Avalonia.PropertyStore
{ {
// Set the value if: there is no current effective value; or // Set the value if: there is no current effective value; or
if (current is null) if (current is null)
return true; return true;
// The value's priority is higher than the current effective value's priority; or // The value's priority is higher than the current effective value's priority; or
if (entryPriority < current.Priority && entryPriority < current.BasePriority) if (entryPriority < current.Priority && entryPriority < current.BasePriority)
@ -1143,7 +1131,7 @@ namespace Avalonia.PropertyStore
} }
private bool TryGetEffectiveValue( private bool TryGetEffectiveValue(
AvaloniaProperty property, AvaloniaProperty property,
[NotNullWhen(true)] out EffectiveValue? value) [NotNullWhen(true)] out EffectiveValue? value)
{ {
if (_effectiveValues.TryGetValue(property, out value)) if (_effectiveValues.TryGetValue(property, out value))

Loading…
Cancel
Save