Skip to content

Commit

Permalink
Only repaint LcdWidget if necessary (#7187)
Browse files Browse the repository at this point in the history
Some analysis done with Callgrind showed that the `LcdWidget` spends quite some time repainting itself even when nothing has changed. Some widget instances are used in song update contexts where `LcdWidget::setValue` is called 60 times per second.

This commit fixes the problem by only updating the `LcdWidget` if its value really has changed.

Adjust the condition in the if-clause so that it becomes clearer what's the interval of interest.
  • Loading branch information
michaelgregorius authored Apr 1, 2024
1 parent c271d28 commit 5d5d8f8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/gui/widgets/LcdWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,26 @@ void LcdWidget::setValue(int value)
}
}

m_display = s;
if (m_display != s)
{
m_display = s;

update();
update();
}
}

void LcdWidget::setValue(float value)
{
if (value < 0 && value > -1)
if (-1 < value && value < 0)
{
QString s = QString::number(static_cast<int>(value));
s.prepend('-');

m_display = s;
update();
if (m_display != s)
{
m_display = s;
update();
}
}
else
{
Expand Down

0 comments on commit 5d5d8f8

Please sign in to comment.