Browse Source

Get rid of static deferredSetter used for PriorityValues. Use a single DeferredSetter for both styled and direct properties.

pull/1732/head
Jeremy Koritzinsky 8 years ago
parent
commit
f11f5bc154
  1. 20
      src/Avalonia.Base/AvaloniaObject.cs
  2. 3
      src/Avalonia.Base/IPriorityValueOwner.cs
  3. 8
      src/Avalonia.Base/PriorityValue.cs
  4. 20
      src/Avalonia.Base/ValueStore.cs

20
src/Avalonia.Base/AvaloniaObject.cs

@ -22,7 +22,7 @@ namespace Avalonia
/// <remarks> /// <remarks>
/// This class is analogous to DependencyObject in WPF. /// This class is analogous to DependencyObject in WPF.
/// </remarks> /// </remarks>
public class AvaloniaObject : IAvaloniaObject, IAvaloniaObjectDebug, INotifyPropertyChanged, IPriorityValueOwner public class AvaloniaObject : IAvaloniaObject, IAvaloniaObjectDebug, INotifyPropertyChanged
{ {
/// <summary> /// <summary>
/// The parent object that inherited values are inherited from. /// The parent object that inherited values are inherited from.
@ -414,9 +414,8 @@ namespace Avalonia
VerifyAccess(); VerifyAccess();
_values?.Revalidate(property); _values?.Revalidate(property);
} }
/// <inheritdoc/> internal void PriorityValueChanged(AvaloniaProperty property, int priority, object oldValue, object newValue)
void IPriorityValueOwner.Changed(AvaloniaProperty property, int priority, object oldValue, object newValue)
{ {
oldValue = (oldValue == AvaloniaProperty.UnsetValue) ? oldValue = (oldValue == AvaloniaProperty.UnsetValue) ?
GetDefaultValue(property) : GetDefaultValue(property) :
@ -439,9 +438,8 @@ namespace Avalonia
(BindingPriority)priority); (BindingPriority)priority);
} }
} }
/// <inheritdoc/> internal void BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification)
void IPriorityValueOwner.BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification)
{ {
UpdateDataValidation(property, notification); UpdateDataValidation(property, notification);
} }
@ -566,15 +564,15 @@ namespace Avalonia
T value) T value)
{ {
Contract.Requires<ArgumentNullException>(setterCallback != null); Contract.Requires<ArgumentNullException>(setterCallback != null);
return DirectPropertyDeferredSetter.SetAndNotify( return _values.Setter.SetAndNotify(
property, property,
ref field, ref field,
(object val, ref T backing, Action<Action> notify) => ((object value, int) update, ref T backing, Action<Action> notify) =>
{ {
setterCallback((T)val, ref backing, notify); setterCallback((T)update.value, ref backing, notify);
return true; return true;
}, },
value); (value, 0));
} }
/// <summary> /// <summary>

3
src/Avalonia.Base/IPriorityValueOwner.cs

@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Utilities;
namespace Avalonia namespace Avalonia
{ {
@ -31,5 +32,7 @@ namespace Avalonia
/// Ensures that the current thread is the UI thread. /// Ensures that the current thread is the UI thread.
/// </summary> /// </summary>
void VerifyAccess(); void VerifyAccess();
DeferredSetter<AvaloniaProperty, (object value, int priority)> Setter { get; }
} }
} }

8
src/Avalonia.Base/PriorityValue.cs

@ -21,7 +21,7 @@ namespace Avalonia
/// priority binding that doesn't return <see cref="AvaloniaProperty.UnsetValue"/>. Where there /// priority binding that doesn't return <see cref="AvaloniaProperty.UnsetValue"/>. Where there
/// are multiple bindings registered with the same priority, the most recently added binding /// are multiple bindings registered with the same priority, the most recently added binding
/// has a higher priority. Each time the value changes, the /// has a higher priority. Each time the value changes, the
/// <see cref="IPriorityValueOwner.Changed(PriorityValue, object, object)"/> method on the /// <see cref="IPriorityValueOwner.Changed"/> method on the
/// owner object is fired with the old and new values. /// owner object is fired with the old and new values.
/// </remarks> /// </remarks>
internal class PriorityValue internal class PriorityValue
@ -30,7 +30,6 @@ namespace Avalonia
private readonly SingleOrDictionary<int, PriorityLevel> _levels = new SingleOrDictionary<int, PriorityLevel>(); private readonly SingleOrDictionary<int, PriorityLevel> _levels = new SingleOrDictionary<int, PriorityLevel>();
private readonly Func<object, object> _validate; private readonly Func<object, object> _validate;
private static readonly DeferredSetter<PriorityValue, (object value, int priority)> delayedSetter = new DeferredSetter<PriorityValue, (object, int)>();
private (object value, int priority) _value; private (object value, int priority) _value;
/// <summary> /// <summary>
@ -243,7 +242,7 @@ namespace Avalonia
/// <param name="priority">The priority level that the value came from.</param> /// <param name="priority">The priority level that the value came from.</param>
private void UpdateValue(object value, int priority) private void UpdateValue(object value, int priority)
{ {
delayedSetter.SetAndNotify(this, Owner.Setter.SetAndNotify(Property,
ref _value, ref _value,
UpdateCore, UpdateCore,
(value, priority)); (value, priority));
@ -256,14 +255,13 @@ namespace Avalonia
{ {
var val = update.value; var val = update.value;
var notification = val as BindingNotification; var notification = val as BindingNotification;
object castValue;
if (notification != null) if (notification != null)
{ {
val = (notification.HasValue) ? notification.Value : null; val = (notification.HasValue) ? notification.Value : null;
} }
if (TypeUtilities.TryConvertImplicit(_valueType, val, out castValue)) if (TypeUtilities.TryConvertImplicit(_valueType, val, out object castValue))
{ {
var old = backing.value; var old = backing.value;

20
src/Avalonia.Base/ValueStore.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Utilities;
namespace Avalonia namespace Avalonia
{ {
@ -91,12 +92,12 @@ namespace Avalonia
public void BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification) public void BindingNotificationReceived(AvaloniaProperty property, BindingNotification notification)
{ {
((IPriorityValueOwner)_owner).BindingNotificationReceived(property, notification); _owner.BindingNotificationReceived(property, notification);
} }
public void Changed(AvaloniaProperty property, int priority, object oldValue, object newValue) public void Changed(AvaloniaProperty property, int priority, object oldValue, object newValue)
{ {
((IPriorityValueOwner)_owner).Changed(property, priority, oldValue, newValue); _owner.PriorityValueChanged(property, priority, oldValue, newValue);
} }
public IDictionary<AvaloniaProperty, PriorityValue> GetSetValues() => throw new NotImplementedException(); public IDictionary<AvaloniaProperty, PriorityValue> GetSetValues() => throw new NotImplementedException();
@ -148,13 +149,11 @@ namespace Avalonia
validate2 = v => validate(_owner, v); validate2 = v => validate(_owner, v);
} }
PriorityValue result = new PriorityValue( return new PriorityValue(
this, this,
property, property,
property.PropertyType, property.PropertyType,
validate2); validate2);
return result;
} }
private object Validate(AvaloniaProperty property, object value) private object Validate(AvaloniaProperty property, object value)
@ -168,5 +167,16 @@ namespace Avalonia
return value; return value;
} }
private DeferredSetter<AvaloniaProperty, (object value, int priority)> _defferedSetter;
public DeferredSetter<AvaloniaProperty, (object value, int priority)> Setter
{
get
{
return _defferedSetter ??
(_defferedSetter = new DeferredSetter<AvaloniaProperty, (object value, int priority)>());
}
}
} }
} }

Loading…
Cancel
Save