diff --git a/src/Core/src/Graphics/MauiDrawable.Android.cs b/src/Core/src/Graphics/MauiDrawable.Android.cs index 35afbaa24ae9..bed6a0124f00 100644 --- a/src/Core/src/Graphics/MauiDrawable.Android.cs +++ b/src/Core/src/Graphics/MauiDrawable.Android.cs @@ -15,6 +15,14 @@ namespace Microsoft.Maui.Graphics { public class MauiDrawable : PaintDrawable { + static Join? JoinMiter; + static Join? JoinBevel; + static Join? JoinRound; + + static Cap? CapButt; + static Cap? CapSquare; + static Cap? CapRound; + readonly AContext? _context; readonly float _density; @@ -298,20 +306,13 @@ public void SetBorderMiterLimit(float strokeMiterLimit) public void SetBorderLineJoin(LineJoin lineJoin) { - Join? aLineJoin = Join.Miter; - - switch (lineJoin) + Join? aLineJoin = lineJoin switch { - case LineJoin.Miter: - aLineJoin = Join.Miter; - break; - case LineJoin.Bevel: - aLineJoin = Join.Bevel; - break; - case LineJoin.Round: - aLineJoin = Join.Round; - break; - } + LineJoin.Miter => JoinMiter ??= Join.Miter, + LineJoin.Bevel => JoinBevel ??= Join.Bevel, + LineJoin.Round => JoinRound ??= Join.Round, + _ => JoinMiter ??= Join.Miter, + }; if (_strokeLineJoin == aLineJoin) return; @@ -323,20 +324,13 @@ public void SetBorderLineJoin(LineJoin lineJoin) public void SetBorderLineCap(LineCap lineCap) { - Cap? aLineCap = Cap.Butt; - - switch (lineCap) + Cap? aLineCap = lineCap switch { - case LineCap.Butt: - aLineCap = Cap.Butt; - break; - case LineCap.Square: - aLineCap = Cap.Square; - break; - case LineCap.Round: - aLineCap = Cap.Round; - break; - } + LineCap.Butt => CapButt ??= Cap.Butt, + LineCap.Square => CapSquare ??= Cap.Square, + LineCap.Round => CapRound ??= Cap.Round, + _ => CapButt ??= Cap.Butt, + }; if (_strokeLineCap == aLineCap) return;