Skip to content

Columns/Main/Meters panels: move const calc expression out of loop#2042

Closed
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:const-out-of-loop3
Closed

Columns/Main/Meters panels: move const calc expression out of loop#2042
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:const-out-of-loop3

Conversation

@GermanAizek

Copy link
Copy Markdown
Contributor

Reference: #2038

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4f5ed4a9-420e-4751-bb45-2714e395cb30

📥 Commits

Reviewing files that changed from the base of the PR and between 1ef4226 and 2745945.

📒 Files selected for processing (3)
  • ColumnsPanel.c
  • MainPanel.c
  • MetersPanel.c

📝 Walkthrough

Walkthrough

This change applies a micro-optimization across ColumnsPanel.c, MainPanel.c, and MetersPanel.c by caching the results of Panel_size(super) or Vector_size(meters) into local const int variables before entering for loops, rather than re-evaluating these functions on each loop iteration. The affected functions are ColumnsPanel_cancelMoving, MainPanel_idSearch, MainPanel_foreachRow, MetersPanel_setMoving, and MetersPanel_new. No control flow, logic, or public API declarations are altered.

Changes

File Change
ColumnsPanel.c Cache Panel_size(super) in ColumnsPanel_cancelMoving
MainPanel.c Cache Panel_size(super) in MainPanel_idSearch and MainPanel_foreachRow
MetersPanel.c Cache Panel_size(super) in MetersPanel_setMoving and Vector_size(meters) in MetersPanel_new

Related issues: None specified.

Related PRs: None specified.

Suggested labels: performance, refactor

Suggested reviewers: htop-dev maintainers familiar with Panel/MetersPanel internals

Poem

A rabbit hopped through loops of old,
Where sizes were fetched, again retold.
Now cached in n, quick and neat,
Fewer calls, a tidier feat.
Hop, hop — the panels run complete. 🐇


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fasterit

Copy link
Copy Markdown
Member

The core team consensus is to leave such optimizations to the compiler for better readability of the code to humans. Closing.

@fasterit fasterit closed this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants