Browse Source
Merge pull request #5528 from MarchingCube/perf-improvements
Reduce memory pressure when using bindings
pull/5538/head
Steven Kirk
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
30 additions and
3 deletions
-
src/Avalonia.Base/Data/BindingOperations.cs
-
src/Avalonia.Base/Reactive/AvaloniaPropertyObservable.cs
|
|
|
@ -45,7 +45,7 @@ namespace Avalonia.Data |
|
|
|
case BindingMode.OneWay: |
|
|
|
return target.Bind(property, binding.Observable ?? binding.Subject, binding.Priority); |
|
|
|
case BindingMode.TwoWay: |
|
|
|
return new CompositeDisposable( |
|
|
|
return new TwoWayBindingDisposable( |
|
|
|
target.Bind(property, binding.Subject, binding.Priority), |
|
|
|
target.GetObservable(property).Subscribe(binding.Subject)); |
|
|
|
case BindingMode.OneTime: |
|
|
|
@ -88,6 +88,32 @@ namespace Avalonia.Data |
|
|
|
throw new ArgumentException("Invalid binding mode."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private sealed class TwoWayBindingDisposable : IDisposable |
|
|
|
{ |
|
|
|
private readonly IDisposable _first; |
|
|
|
private readonly IDisposable _second; |
|
|
|
private bool _isDisposed; |
|
|
|
|
|
|
|
public TwoWayBindingDisposable(IDisposable first, IDisposable second) |
|
|
|
{ |
|
|
|
_first = first; |
|
|
|
_second = second; |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
{ |
|
|
|
if (_isDisposed) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
_first.Dispose(); |
|
|
|
_second.Dispose(); |
|
|
|
|
|
|
|
_isDisposed = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public sealed class DoNothingType |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
namespace Avalonia.Reactive |
|
|
|
{ |
|
|
|
@ -55,9 +56,9 @@ namespace Avalonia.Reactive |
|
|
|
newValue = (T)e.Sender.GetValue(e.Property); |
|
|
|
} |
|
|
|
|
|
|
|
if (!Equals(newValue, _value)) |
|
|
|
if (!EqualityComparer<T>.Default.Equals(newValue, _value)) |
|
|
|
{ |
|
|
|
_value = (T)newValue; |
|
|
|
_value = newValue; |
|
|
|
PublishNext(_value); |
|
|
|
} |
|
|
|
} |
|
|
|
|