From 8eb0f4127a21bf4da4bb783334c2ee0f3c80941b Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sun, 3 Nov 2019 16:18:12 +0100 Subject: [PATCH] Save up to two value lookups when applying layout constraints. --- src/Avalonia.Layout/LayoutHelper.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Layout/LayoutHelper.cs b/src/Avalonia.Layout/LayoutHelper.cs index d77cc269f9..cfb4b14b1c 100644 --- a/src/Avalonia.Layout/LayoutHelper.cs +++ b/src/Avalonia.Layout/LayoutHelper.cs @@ -21,8 +21,11 @@ namespace Avalonia.Layout /// The control's size. public static Size ApplyLayoutConstraints(ILayoutable control, Size constraints) { - double width = (control.Width > 0) ? control.Width : constraints.Width; - double height = (control.Height > 0) ? control.Height : constraints.Height; + var controlWidth = control.Width; + var controlHeight = control.Height; + + double width = (controlWidth > 0) ? controlWidth : constraints.Width; + double height = (controlHeight > 0) ? controlHeight : constraints.Height; width = Math.Min(width, control.MaxWidth); width = Math.Max(width, control.MinWidth); height = Math.Min(height, control.MaxHeight);