Răsfoiți Sursa

Fixes Pos/Dim static fields not being disposing. (#2929)

BDisp 1 an în urmă
părinte
comite
c0da565baf
1 a modificat fișierele cu 15 adăugiri și 41 ștergeri
  1. 15 41
      Terminal.Gui/View/Layout/PosDim.cs

+ 15 - 41
Terminal.Gui/View/Layout/PosDim.cs

@@ -118,8 +118,6 @@ namespace Terminal.Gui {
 			return new PosFactor (n / 100);
 		}
 
-		static PosAnchorEnd endNoMargin;
-
 		internal class PosAnchorEnd : Pos {
 			int n;
 
@@ -137,6 +135,10 @@ namespace Terminal.Gui {
 			{
 				return $"AnchorEnd({n})";
 			}
+
+			public override int GetHashCode () => n.GetHashCode ();
+
+			public override bool Equals (object other) => other is PosAnchorEnd anchorEnd && anchorEnd.n == n;
 		}
 
 		/// <summary>
@@ -158,11 +160,6 @@ namespace Terminal.Gui {
 			if (margin < 0)
 				throw new ArgumentException ("Margin must be positive");
 
-			if (margin == 0) {
-				if (endNoMargin == null)
-					endNoMargin = new PosAnchorEnd (0);
-				return endNoMargin;
-			}
 			return new PosAnchorEnd (margin);
 		}
 
@@ -178,8 +175,6 @@ namespace Terminal.Gui {
 			}
 		}
 
-		static PosCenter pCenter;
-
 		/// <summary>
 		/// Returns a <see cref="Pos"/> object that can be used to center the <see cref="View"/>
 		/// </summary>
@@ -198,9 +193,7 @@ namespace Terminal.Gui {
 		/// </example>
 		public static Pos Center ()
 		{
-			if (pCenter == null)
-				pCenter = new PosCenter ();
-			return pCenter;
+			return new PosCenter ();
 		}
 
 		internal class PosAbsolute : Pos {
@@ -269,8 +262,6 @@ namespace Terminal.Gui {
 
 		}
 
-		static PosCombine posCombine;
-
 		/// <summary>
 		/// Adds a <see cref="Terminal.Gui.Pos"/> to a <see cref="Terminal.Gui.Pos"/>, yielding a new <see cref="Pos"/>.
 		/// </summary>
@@ -280,12 +271,11 @@ namespace Terminal.Gui {
 		public static Pos operator + (Pos left, Pos right)
 		{
 			if (left is PosAbsolute && right is PosAbsolute) {
-				posCombine = null;
 				return new PosAbsolute (left.Anchor (0) + right.Anchor (0));
 			}
 			PosCombine newPos = new PosCombine (true, left, right);
 			SetPosCombine (left, newPos);
-			return posCombine = newPos;
+			return newPos;
 		}
 
 		/// <summary>
@@ -297,21 +287,18 @@ namespace Terminal.Gui {
 		public static Pos operator - (Pos left, Pos right)
 		{
 			if (left is PosAbsolute && right is PosAbsolute) {
-				posCombine = null;
 				return new PosAbsolute (left.Anchor (0) - right.Anchor (0));
 			}
 			PosCombine newPos = new PosCombine (false, left, right);
 			SetPosCombine (left, newPos);
-			return posCombine = newPos;
+			return newPos;
 		}
 
 		static void SetPosCombine (Pos left, PosCombine newPos)
 		{
-			if (posCombine?.ToString () != newPos.ToString ()) {
-				var view = left as PosView;
-				if (view != null) {
-					view.Target.SetNeedsLayout ();
-				}
+			var view = left as PosView;
+			if (view != null) {
+				view.Target.SetNeedsLayout ();
 			}
 		}
 
@@ -555,8 +542,6 @@ namespace Terminal.Gui {
 			public override bool Equals (object other) => other is DimFill fill && fill.margin == margin;
 		}
 
-		static DimFill zeroMargin;
-
 		/// <summary>
 		/// Initializes a new instance of the <see cref="Dim"/> class that fills the dimension, but leaves the specified number of colums for a margin.
 		/// </summary>
@@ -564,11 +549,6 @@ namespace Terminal.Gui {
 		/// <param name="margin">Margin to use.</param>
 		public static Dim Fill (int margin = 0)
 		{
-			if (margin == 0) {
-				if (zeroMargin == null)
-					zeroMargin = new DimFill (0);
-				return zeroMargin;
-			}
 			return new DimFill (margin);
 		}
 
@@ -619,8 +599,6 @@ namespace Terminal.Gui {
 
 		}
 
-		static DimCombine dimCombine;
-
 		/// <summary>
 		/// Adds a <see cref="Terminal.Gui.Dim"/> to a <see cref="Terminal.Gui.Dim"/>, yielding a new <see cref="Dim"/>.
 		/// </summary>
@@ -630,12 +608,11 @@ namespace Terminal.Gui {
 		public static Dim operator + (Dim left, Dim right)
 		{
 			if (left is DimAbsolute && right is DimAbsolute) {
-				dimCombine = null;
 				return new DimAbsolute (left.Anchor (0) + right.Anchor (0));
 			}
 			DimCombine newDim = new DimCombine (true, left, right);
 			SetDimCombine (left, newDim);
-			return dimCombine = newDim;
+			return newDim;
 		}
 
 		/// <summary>
@@ -647,21 +624,18 @@ namespace Terminal.Gui {
 		public static Dim operator - (Dim left, Dim right)
 		{
 			if (left is DimAbsolute && right is DimAbsolute) {
-				dimCombine = null;
 				return new DimAbsolute (left.Anchor (0) - right.Anchor (0));
 			}
 			DimCombine newDim = new DimCombine (false, left, right);
 			SetDimCombine (left, newDim);
-			return dimCombine = newDim;
+			return newDim;
 		}
 
 		static void SetDimCombine (Dim left, DimCombine newPos)
 		{
-			if (dimCombine?.ToString () != newPos.ToString ()) {
-				var view = left as DimView;
-				if (view != null) {
-					view.Target.SetNeedsLayout ();
-				}
+			var view = left as DimView;
+			if (view != null) {
+				view.Target.SetNeedsLayout ();
 			}
 		}