Skip to content

CTabFolder: Improve readability, performance, simplification, and test coverage #3219

@vogella

Description

@vogella

Overview

CTabFolder (4,257 lines), CTabFolderRenderer (1,338 lines), CTabItem (540 lines), and CTabFolderLayout (123 lines) have significant opportunities for improvement in readability, performance, code simplification, and test coverage.


1. Readability Improvements

  • Extract and simplify updateItems() (CTabFolder): 83-line method with 4 near-identical loops computing tab widths. Extract into helper methods and add comments explaining the priority-based visibility algorithm.
  • Split drawSelected() (CTabFolderRenderer): 187-line method with deep nesting and shape array index arithmetic. Split into shape construction, highlight drawing, and text rendering.
  • Split computeControlBounds() (CTabFolder): 182-line method mixing layout, positioning, and wrapping. Split into leading/trailing control computation.
  • Replace magic numbers with named constants: e.g. 16 for button width (CTabFolder), unnamed margins/spacing in CTabFolderRenderer.
  • Fix misleading field initialization in CTabItem: int x,y,width,height = 0; — only height is explicitly initialized (others default to 0 by JLS but this is misleading).

2. Performance Improvements

  • Replace array copying in addTabControl()/removeTabControl() (CTabFolder): 4 parallel arrays are fully copied on each add/remove. Use ArrayList or grow-by-factor strategy.
  • Cache renderer.computeSize() results in updateItems(): Called 4+ times per item in nested loops. Cache results to avoid redundant computation.
  • Avoid Rectangle allocation on every mouse move (CTabFolder onMouseMove()): Reuse a field instead of new Rectangle() in hot path.
  • Reduce Region allocation in drawBackground() (CTabFolderRenderer): Creates and disposes Region objects on every call.
  • Cache chevron image in updateChevronImage(): Currently disposes and recreates on every call.

3. Code Simplification

  • Extract duplicate min/max button logic in updateButtons() (CTabFolder): Near-identical blocks for min/max button creation. Extract to shared helper method.
  • Unify close button positioning in setItemLocation() (CTabFolder): Separate code paths for single/multi mode share most logic — consolidate.
  • Consolidate drawBackground() overloads (CTabFolderRenderer): 3 overloads with nearly identical logic.
  • Extract repeated null-coalescing pattern in CTabItem: getForeground(), getSelectionForeground(), getFont() are identical patterns.
  • Simplify setSelectionBackground() (CTabFolder): 81 lines, 66 of which are validation/comparison. Extract colorsEqual() helper.
  • Remove or document commented-out code (CTabItem) and consider timeline for deprecated field removal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions