From 8f49725c8fa762a5bf76277279e91b4c1bf51476 Mon Sep 17 00:00:00 2001 From: Lachlan Ennis <2433737+elachlan@users.noreply.github.com> Date: Thu, 10 Nov 2022 08:06:02 +1000 Subject: [PATCH 1/2] Refactor TableLayout to replace ArrayList --- .../src/System/Windows/Forms/Layout/TableLayout.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs index 1007f411bd2..9e6b245f2f4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs @@ -765,7 +765,7 @@ private static int InflateColumns(ContainerInfo containerInfo, Size proposedCons Strip strip = strips[i]; if (i < styles.Count) { - TableLayoutStyle style = (TableLayoutStyle)styles[i]; + TableLayoutStyle style = styles[i]; if (style.SizeType == SizeType.Percent) { totalPercent += style.Size; @@ -784,7 +784,7 @@ private static int InflateColumns(ContainerInfo containerInfo, Size proposedCons { if (i < styles.Count) { - TableLayoutStyle style = (TableLayoutStyle)styles[i]; + TableLayoutStyle style = styles[i]; if (style.SizeType == SizeType.Percent) { float percentageOfTotal = style.Size / (float)totalPercent; @@ -1207,7 +1207,7 @@ private static void SetElementBounds(ContainerInfo containerInfo, RectangleF dis Sort(childrenInfo, PostAssignedPositionComparer.GetInstance); for (int i = 0; i < childrenInfo.Length; i++) { - LayoutInfo layoutInfo = (LayoutInfo)childrenInfo[i]; + LayoutInfo layoutInfo = childrenInfo[i]; IArrangedElement element = layoutInfo.Element; @@ -1487,7 +1487,7 @@ private static void Debug_VerifyNoOverlapping(IArrangedElement container) // this code may be useful for debugging, but doesnt work well with // row styles - ArrayList layoutInfos = new ArrayList(container.Children.Count); + List layoutInfos = new List(container.Children.Count); ContainerInfo containerInfo = GetContainerInfo(container); Strip[] rows = containerInfo.Rows; Strip[] columns = containerInfo.Columns; @@ -1506,13 +1506,13 @@ private static void Debug_VerifyNoOverlapping(IArrangedElement container) for (int i = 0; i < layoutInfos.Count; i++) { - LayoutInfo layoutInfo1 = (LayoutInfo)layoutInfos[i]; + LayoutInfo layoutInfo1 = layoutInfos[i]; Rectangle elementBounds1 = layoutInfo1.Element.Bounds; Rectangle cellsOccupied1 = new Rectangle(layoutInfo1.ColumnStart, layoutInfo1.RowStart, layoutInfo1.ColumnSpan, layoutInfo1.RowSpan); for (int j = i + 1; j < layoutInfos.Count; j++) { - LayoutInfo layoutInfo2 = (LayoutInfo)layoutInfos[j]; + LayoutInfo layoutInfo2 = layoutInfos[j]; Rectangle elementBounds2 = layoutInfo2.Element.Bounds; Rectangle cellsOccupied2 = new Rectangle(layoutInfo2.ColumnStart, layoutInfo2.RowStart, layoutInfo2.ColumnSpan, layoutInfo2.RowSpan); Debug.Assert(!cellsOccupied1.IntersectsWith(cellsOccupied2), "controls overlap in the same cell"); From 407fdbc9c1827ba55c52126fb61129d39e0a8b46 Mon Sep 17 00:00:00 2001 From: Lachlan Ennis <2433737+elachlan@users.noreply.github.com> Date: Thu, 10 Nov 2022 10:50:26 +1000 Subject: [PATCH 2/2] Changes from review Additional missed ArryList and HashTable --- .../src/System/Windows/Forms/Layout/TableLayout.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs index 9e6b245f2f4..a3d59562db4 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Layout/TableLayout.cs @@ -1421,9 +1421,9 @@ internal static ContainerInfo GetContainerInfo(IArrangedElement container) private static void Debug_VerifyAssignmentsAreCurrent(IArrangedElement container, ContainerInfo containerInfo) { #if DEBUG - Hashtable oldLayoutInfo = new Hashtable(); + Dictionary oldLayoutInfo = new(); ArrangedElementCollection children = container.Children; - ArrayList childrenInfo = new ArrayList(children.Count); + List childrenInfo = new(children.Count); int minSpace = 0; int minColumn = 0; @@ -1466,10 +1466,10 @@ private static void Debug_VerifyAssignmentsAreCurrent(IArrangedElement container { Debug.Assert(layoutInfo.Equals(oldLayoutInfo[layoutInfo.Element]), "Cached assignment info is invalid: LayoutInfo has changed." - + " old layoutinfo: " + ((LayoutInfo)oldLayoutInfo[layoutInfo.Element]).RowStart + " " + ((LayoutInfo)oldLayoutInfo[layoutInfo.Element]).ColumnStart + + " old layoutinfo: " + oldLayoutInfo[layoutInfo.Element].RowStart + " " + oldLayoutInfo[layoutInfo.Element].ColumnStart + " new layoutinfo: " + layoutInfo.RowStart + " " + layoutInfo.ColumnStart + " and the element is " + layoutInfo.Element.ToString()); - SetLayoutInfo(layoutInfo.Element, (LayoutInfo)oldLayoutInfo[layoutInfo.Element]); + SetLayoutInfo(layoutInfo.Element, oldLayoutInfo[layoutInfo.Element]); } // Restore the information in row and column strips. Note that whenever we do a AssignRowAndColumns() @@ -1487,7 +1487,7 @@ private static void Debug_VerifyNoOverlapping(IArrangedElement container) // this code may be useful for debugging, but doesnt work well with // row styles - List layoutInfos = new List(container.Children.Count); + List layoutInfos = new(container.Children.Count); ContainerInfo containerInfo = GetContainerInfo(container); Strip[] rows = containerInfo.Rows; Strip[] columns = containerInfo.Columns;