Browse Source

Merge pull request #2964 from MarchingCube/alloc-effectivelyenabled

Avoid allocations when running UpdateIsEffectivelyEnabled.
pull/2970/head
danwalmsley 7 years ago
committed by GitHub
parent
commit
61803578e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      src/Avalonia.Input/InputElement.cs

12
src/Avalonia.Input/InputElement.cs

@ -565,9 +565,17 @@ namespace Avalonia.Input
{ {
IsEffectivelyEnabled = IsEnabledCore && (parent?.IsEffectivelyEnabled ?? true); IsEffectivelyEnabled = IsEnabledCore && (parent?.IsEffectivelyEnabled ?? true);
foreach (var child in this.GetVisualChildren().OfType<InputElement>()) // PERF-SENSITIVE: This is called on entire hierarchy and using foreach or LINQ
// will cause extra allocations and overhead.
var children = VisualChildren;
// ReSharper disable once ForCanBeConvertedToForeach
for (int i = 0; i < children.Count; ++i)
{ {
child.UpdateIsEffectivelyEnabled(this); var child = children[i] as InputElement;
child?.UpdateIsEffectivelyEnabled(this);
} }
} }
} }

Loading…
Cancel
Save