From 2745945cb0c96ce3dc93189dfc3e874dcd607b67 Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Wed, 8 Jul 2026 05:46:41 +0300 Subject: [PATCH] Columns/Main/Meters panels: move const calc expression out of loop --- ColumnsPanel.c | 3 ++- MainPanel.c | 6 ++++-- MetersPanel.c | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 42db11506..3dc6fa140 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -36,7 +36,8 @@ static void ColumnsPanel_delete(Object* object) { static void ColumnsPanel_cancelMoving(ColumnsPanel* this) { Panel* super = &this->super; - for (int i = 0; i < Panel_size(super); i++) { + const int n = Panel_size(super); + for (int i = 0; i < n; i++) { ListItem* item = (ListItem*) Panel_get(super, i); if (item) item->moving = false; diff --git a/MainPanel.c b/MainPanel.c index ede854224..b699e8548 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -38,7 +38,8 @@ void MainPanel_updateLabels(MainPanel* this, bool list, bool filter) { static void MainPanel_idSearch(MainPanel* this, int ch) { Panel* super = &this->super; pid_t id = ch - 48 + this->idSearch; - for (int i = 0; i < Panel_size(super); i++) { + const int n = Panel_size(super); + for (int i = 0; i < n; i++) { const Row* row = (const Row*) Panel_get(super, i); if (row && row->id == id) { Panel_setSelected(super, i); @@ -181,7 +182,8 @@ bool MainPanel_foreachRow(MainPanel* this, MainPanel_foreachRowFn fn, Arg arg, b Panel* super = &this->super; bool ok = true; bool anyTagged = false; - for (int i = 0; i < Panel_size(super); i++) { + const int n = Panel_size(super); + for (int i = 0; i < n; i++) { Row* row = (Row*) Panel_get(super, i); if (row->tag) { ok &= fn(row, arg); diff --git a/MetersPanel.c b/MetersPanel.c index 418229e2d..8c2130cc2 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -53,7 +53,8 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) { this->moving = moving; if (!moving) { /* Reset all items' moving flags when canceling move mode */ - for (int i = 0; i < Panel_size(super); i++) { + const int n = Panel_size(super); + for (int i = 0; i < n; i++) { ListItem* item = (ListItem*) Panel_get(super, i); if (item) item->moving = false; @@ -223,7 +224,8 @@ MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* met this->rightNeighbor = NULL; this->leftNeighbor = NULL; Panel_setHeader(super, header); - for (int i = 0; i < Vector_size(meters); i++) { + const int n = Vector_size(meters); + for (int i = 0; i < n; i++) { const Meter* meter = (const Meter*) Vector_get(meters, i); Panel_add(super, (Object*) Meter_toListItem(meter, false)); }