Skip to content

Commit b43390a

Browse files
Copilottig
andauthored
Fixes gui-cs#4677 - Refactors DimAuto for less coupling and improves performance (gui-cs#4678)
* Phase 5: Add IsFixed and RequiresTargetLayout categorization properties Co-authored-by: tig <585482+tig@users.noreply.github.com> * Further simplify DimAuto.Calculate using IsFixed property Co-authored-by: tig <585482+tig@users.noreply.github.com> * Refactor for-loops to foreach and clarify DimFill logic Refactored multiple for-loops iterating over view lists to use foreach loops for improved readability and reduced boilerplate. Removed unused variables such as viewsNeedingLayout and index counters. Clarified DimFill handling by continuing early if the DimFill is not valid or lacks a To property, reducing nesting and improving intent. Made minor formatting and code style improvements for consistency. * Refactor subview filtering and sizing logic Refactored repeated LINQ queries for subview filtering into reusable helper methods (`GetViewsThatMatch`, `GetViewsThatHavePos<TPos>`, `GetViewsThatHaveDim<TDim>`), reducing duplication and improving readability. Moved max content size calculations for various subview types into new helper methods (`GetMaxSizePos<TPos>`, `GetMaxSizeDim<TDim>`). Updated main logic to use these helpers. Adornment thickness calculation now uses a switch expression. These changes improve modularity and maintainability. * Refactor subview categorization for layout calculation Refactored layout calculation to use a single-pass CategorizeSubViews method, grouping subviews by relevant Pos/Dim types into a new CategorizedViews struct. This replaces multiple helper methods and reduces redundant iterations. Updated main logic to use these categorized lists, and unified size calculation helpers to further reduce code duplication. Improves performance and maintainability by consolidating subview processing and removing obsolete methods. * Revert perf POC commits and add missing overrides to Combine types Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add helper methods and simplify DimAuto.Calculate with foreach loops Co-authored-by: tig <585482+tig@users.noreply.github.com> * Refactor layout calculation in DimAuto.cs Removed commented-out code and unnecessary list declarations to clean up the layout calculation logic. * removed old plan file * Code cleanup * Add performance analysis and improvement plan for DimAuto.Calculate Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add DimAuto benchmarks and benchmark documentation Co-authored-by: tig <585482+tig@users.noreply.github.com> * Implement Phase 1 & 2 performance optimizations for DimAuto.Calculate Co-authored-by: tig <585482+tig@users.noreply.github.com> * Code cleanup * Delete plans/dimauto-perf-plan.md --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com> Co-authored-by: Tig <tig@users.noreply.github.com>
1 parent e9976da commit b43390a

File tree

16 files changed

+754
-270
lines changed

16 files changed

+754
-270
lines changed

Terminal.Gui/ViewBase/Layout/Dim.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,44 @@ internal virtual int Calculate (int location, int superviewContentSize, View us,
485485
internal virtual int GetMinimumContribution (int location, int superviewContentSize, View us, Dimension dimension) =>
486486
Calculate (location, superviewContentSize, us, dimension);
487487

488+
/// <summary>
489+
/// Indicates whether this Dim has a fixed value that doesn't depend on layout calculations.
490+
/// </summary>
491+
/// <remarks>
492+
/// <para>
493+
/// This property is used by <see cref="DimAuto"/> to identify dimensions that can be
494+
/// determined without performing layout calculations on other views.
495+
/// </para>
496+
/// <para>
497+
/// Fixed dimensions include <see cref="DimAbsolute"/> and dimensions calculated by
498+
/// <see cref="DimFunc"/> that don't depend on other views' layouts.
499+
/// </para>
500+
/// </remarks>
501+
/// <returns>
502+
/// <see langword="true"/> if this Dim has a fixed value independent of layout;
503+
/// otherwise, <see langword="false"/>.
504+
/// </returns>
505+
internal virtual bool IsFixed => false;
506+
507+
/// <summary>
508+
/// Indicates whether this Dim requires the target view to be laid out before it can be calculated.
509+
/// </summary>
510+
/// <remarks>
511+
/// <para>
512+
/// This property is used by <see cref="DimAuto"/> to identify dimensions that depend on
513+
/// another view's layout being completed first.
514+
/// </para>
515+
/// <para>
516+
/// Dimensions that require target layout include <see cref="DimView"/> which depends on
517+
/// the target view's calculated size.
518+
/// </para>
519+
/// </remarks>
520+
/// <returns>
521+
/// <see langword="true"/> if this Dim requires the target view's layout to be calculated first;
522+
/// otherwise, <see langword="false"/>.
523+
/// </returns>
524+
internal virtual bool RequiresTargetLayout => false;
525+
488526
#endregion virtual methods
489527

490528
#region operators

Terminal.Gui/ViewBase/Layout/DimAbsolute.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ public record DimAbsolute (int Size) : Dim
2323
internal override int GetAnchor (int size) => Size;
2424

2525
internal override int Calculate (int location, int superviewContentSize, View us, Dimension dimension) => Math.Max (GetAnchor (0), 0);
26+
27+
/// <inheritdoc/>
28+
internal override bool IsFixed => true;
2629
}

0 commit comments

Comments
 (0)