mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-03 02:36:11 +00:00
perf(ui): drop redundant getTextWidth and contact re-fetch in QuickMsg
- DM/channel history rows precomputed age_w (= getTextWidth(age) + 3) but then called getTextWidth(age) again to place the cursor. Reuse age_w. - Contact-by-message-count sort fetched each contact twice: once when building _sorted, once when filling counts[]. Fold counts[] into the build loop so each contact is fetched once. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
6410a346f2
commit
71e1cb7a23
@@ -245,17 +245,15 @@ class QuickMsgScreen : public UIScreen {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bool show_all = (p && p->dm_show_all);
|
bool show_all = (p && p->dm_show_all);
|
||||||
|
// Build _sorted and counts[] in one pass — avoids a second getContactByIdx loop.
|
||||||
|
int counts[MAX_CONTACTS];
|
||||||
for (int i = 0; i < total; i++) {
|
for (int i = 0; i < total; i++) {
|
||||||
if (!the_mesh.getContactByIdx(i, c) || c.type != ADV_TYPE_CHAT) continue;
|
if (!the_mesh.getContactByIdx(i, c) || c.type != ADV_TYPE_CHAT) continue;
|
||||||
if (!show_all && !(c.flags & 0x01)) continue;
|
if (!show_all && !(c.flags & 0x01)) continue;
|
||||||
|
counts[_num_contacts] = dmHistCountForContact(c.id.pub_key);
|
||||||
_sorted[_num_contacts++] = i;
|
_sorted[_num_contacts++] = i;
|
||||||
}
|
}
|
||||||
// Sort by message count descending; contacts with no messages keep original order.
|
// Sort by message count descending; contacts with no messages keep original order.
|
||||||
int counts[MAX_CONTACTS];
|
|
||||||
for (int i = 0; i < _num_contacts; i++) {
|
|
||||||
the_mesh.getContactByIdx(_sorted[i], c);
|
|
||||||
counts[i] = dmHistCountForContact(c.id.pub_key);
|
|
||||||
}
|
|
||||||
for (int i = 1; i < _num_contacts; i++) {
|
for (int i = 1; i < _num_contacts; i++) {
|
||||||
if (counts[i] == 0) continue;
|
if (counts[i] == 0) continue;
|
||||||
uint16_t key = _sorted[i]; int kc = counts[i];
|
uint16_t key = _sorted[i]; int kc = counts[i];
|
||||||
@@ -665,7 +663,7 @@ public:
|
|||||||
display.fillRect(0, y, display.width(), hist_box_h);
|
display.fillRect(0, y, display.width(), hist_box_h);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
||||||
if (age[0]) { display.setCursor(display.width() - 3 - display.getTextWidth(age), y + 1); display.print(age); }
|
if (age[0]) { display.setCursor(display.width() - age_w, y + 1); display.print(age); }
|
||||||
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(e.text));
|
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(e.text));
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -673,7 +671,7 @@ public:
|
|||||||
display.fillRect(1, y + 1, display.width() - 2, lh);
|
display.fillRect(1, y + 1, display.width() - 2, lh);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
||||||
if (age[0]) { display.setCursor(display.width() - 3 - display.getTextWidth(age), y + 1); display.print(age); }
|
if (age[0]) { display.setCursor(display.width() - age_w, y + 1); display.print(age); }
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(e.text));
|
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(e.text));
|
||||||
}
|
}
|
||||||
@@ -780,7 +778,7 @@ public:
|
|||||||
display.fillRect(0, y, display.width(), hist_box_h);
|
display.fillRect(0, y, display.width(), hist_box_h);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
||||||
if (age[0]) { display.setCursor(display.width() - 3 - display.getTextWidth(age), y + 1); display.print(age); }
|
if (age[0]) { display.setCursor(display.width() - age_w, y + 1); display.print(age); }
|
||||||
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(msg_part));
|
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(msg_part));
|
||||||
} else {
|
} else {
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
@@ -788,7 +786,7 @@ public:
|
|||||||
display.fillRect(1, y + 1, display.width() - 2, lh);
|
display.fillRect(1, y + 1, display.width() - 2, lh);
|
||||||
display.setColor(DisplayDriver::DARK);
|
display.setColor(DisplayDriver::DARK);
|
||||||
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
display.drawTextEllipsized(3, y + 1, display.width() - cw - 2 - age_w, sender);
|
||||||
if (age[0]) { display.setCursor(display.width() - 3 - display.getTextWidth(age), y + 1); display.print(age); }
|
if (age[0]) { display.setCursor(display.width() - age_w, y + 1); display.print(age); }
|
||||||
display.setColor(DisplayDriver::LIGHT);
|
display.setColor(DisplayDriver::LIGHT);
|
||||||
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(msg_part));
|
display.drawTextEllipsized(3, y + lh + 1, display.width() - cw - 2, skipReplyPrefix(msg_part));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user