From 66879df3494451c44b68b2094ed19b692377acdb Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 30 Oct 2021 14:47:58 +0100 Subject: [PATCH] Improved the performance of resizing the hex viewer widget, by only recalculating the byte item positions when absolutely necessary. --- .../HexViewerWidget/ByteItemGraphicsScene.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp index cdca7e68..d3eef13b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetMemoryInspectionPane/HexViewerWidget/ByteItemGraphicsScene.cpp @@ -66,9 +66,6 @@ void ByteItemGraphicsScene::updateValues(const Targets::TargetMemoryBuffer& buff } void ByteItemGraphicsScene::adjustByteWidgets() { - std::map> byteWidgetsByRowIndex; - std::map> byteWidgetsByColumnIndex; - const auto margins = QMargins(10, 10, 10, 10); const auto width = std::max(600, static_cast(this->parent->width())); @@ -81,6 +78,21 @@ void ByteItemGraphicsScene::adjustByteWidgets() { std::ceil(static_cast(this->byteWidgetsByAddress.size()) / static_cast(rowCapacity)) ); + this->setSceneRect( + 0, + 0, + width, + (rowCount * byteWidgetHeight) + margins.top() + margins.bottom() + ); + + // Don't bother recalculating the byte item positions if the number of rows have not changed. + if (rowCount == this->byteWidgetsByRowIndex.size()) { + return; + } + + std::map> byteWidgetsByRowIndex; + std::map> byteWidgetsByColumnIndex; + for (auto& [address, byteWidget] : this->byteWidgetsByAddress) { const auto rowIndex = static_cast( std::ceil(static_cast(byteWidget->byteIndex + 1) / static_cast(rowCapacity)) - 1 @@ -104,11 +116,6 @@ void ByteItemGraphicsScene::adjustByteWidgets() { byteWidget->update(); } - const auto minHeight = (rowCount * byteWidgetHeight) + margins.top() + margins.bottom(); -// this->setMinimumHeight(minHeight); - this->setSceneRect(0, 0, width, minHeight); -// this->parent->setMinimumHeight(minHeight); - this->byteWidgetsByRowIndex = std::move(byteWidgetsByRowIndex); this->byteWidgetsByColumnIndex = std::move(byteWidgetsByColumnIndex);