From 6f0caabcf71238a73ddc9c4f57dfefb97f441981 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 15 Feb 2025 21:22:55 -0500 Subject: [PATCH] HaikuDepot: Re-invalidate and re-derive labels in ItemCountView sporadically. Instead of unconditionally calling _DeriveLabel() and Invalidate() every time (both expensive operations), use a bool to track whether we've already invalidated, and derive the label in Draw() if it was set. Significantly decreases the invalidations done on full-list rebuilds. --- src/apps/haikudepot/ui/PackageListView.cpp | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/apps/haikudepot/ui/PackageListView.cpp b/src/apps/haikudepot/ui/PackageListView.cpp index d6b7651167..2ce4fcee0e 100644 --- a/src/apps/haikudepot/ui/PackageListView.cpp +++ b/src/apps/haikudepot/ui/PackageListView.cpp @@ -801,7 +801,8 @@ public: ItemCountView() : BView("item count view", B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE), - fItemCount(0) + fItemCount(0), + fInvalidated(false) { BFont font(be_plain_font); font.SetSize(font.Size() * 0.75f); @@ -834,6 +835,11 @@ public: virtual void Draw(BRect updateRect) { + if (fInvalidated) { + fLabel = _DeriveLabel(fItemCount); + fInvalidated = false; + } + FillRect(updateRect, B_SOLID_LOW); font_height fontHeight; @@ -855,19 +861,20 @@ public: { if (count == fItemCount) return; + fItemCount = count; - fLabel = _DeriveLabel(fItemCount); - Invalidate(); + if (!fInvalidated) { + Invalidate(); + fInvalidated = true; + } } private: - -/*! This method is hit quite often when the list of packages in the - table-view are updated. Derivation of the plural for some - languages such as Russian can be slow so this method should be - called sparingly. -*/ - + /*! This method is hit quite often when the list of packages in the + table-view are updated. Derivation of the plural for some + languages such as Russian can be slow so this method should be + called sparingly. + */ BString _DeriveLabel(int32 count) const { static BStringFormat format(B_TRANSLATE("{0, plural, " @@ -877,9 +884,12 @@ private: return label; } +private: int32 fItemCount; BString fLabel; BSize fMinSize; + + bool fInvalidated; };