From 5d5d8f8f1424949fcd77d1a4a39eeb5479a0a10a Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Mon, 1 Apr 2024 14:57:43 +0200 Subject: [PATCH] Only repaint LcdWidget if necessary (#7187) 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. --- src/gui/widgets/LcdWidget.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/LcdWidget.cpp b/src/gui/widgets/LcdWidget.cpp index fa7dea1da..b30195d6c 100644 --- a/src/gui/widgets/LcdWidget.cpp +++ b/src/gui/widgets/LcdWidget.cpp @@ -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(value)); s.prepend('-'); - m_display = s; - update(); + if (m_display != s) + { + m_display = s; + update(); + } } else {