HaikuDepot : Performance for Package List Updates

Performance improvements for the application updating
lists of packages when the user is operating with the
locale set to Russian.

fixes #14513

Change-Id: I1e2514a2afbd43503ac0edfe280a856411738026
Reviewed-on: https://review.haiku-os.org/612
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Andrew Lindesay
2018-10-04 19:45:52 +00:00
committed by waddlesplash
parent 3a44db1167
commit 6d18e980e1
2 changed files with 27 additions and 12 deletions
+6
View File
@@ -936,6 +936,9 @@ MainWindow::_RefreshPackageList(bool force)
if (fSinglePackageMode) if (fSinglePackageMode)
return; return;
if (Logger::IsDebugEnabled())
printf("will refresh the package list\n");
BPackageRoster roster; BPackageRoster roster;
BStringList repositoryNames; BStringList repositoryNames;
@@ -1221,6 +1224,9 @@ MainWindow::_RefreshPackageList(bool force)
printf("Unknown exception occurred while resolving system " printf("Unknown exception occurred while resolving system "
"dependencies.\n"); "dependencies.\n");
} }
if (Logger::IsDebugEnabled())
printf("did refresh the package list\n");
} }
+21 -12
View File
@@ -1,4 +1,5 @@
/* /*
* Copyright 2018, Andrew Lindesay, <[email protected]>.
* Copyright 2017, Julian Harnath, <[email protected]>. * Copyright 2017, Julian Harnath, <[email protected]>.
* Copyright 2015, Axel Dörfler, <[email protected]>. * Copyright 2015, Axel Dörfler, <[email protected]>.
* Copyright 2013-2014, Stephan Aßmus <[email protected]>. * Copyright 2013-2014, Stephan Aßmus <[email protected]>.
@@ -663,12 +664,16 @@ public:
SetViewUIColor(B_PANEL_BACKGROUND_COLOR); SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
SetLowUIColor(ViewUIColor()); SetLowUIColor(ViewUIColor());
SetHighUIColor(LowUIColor(), B_DARKEN_4_TINT); SetHighUIColor(LowUIColor(), B_DARKEN_4_TINT);
// constantly calculating the size is expensive so here a sensible
// upper limit on the number of packages is arbitrarily chosen.
fMinSize = BSize(StringWidth(_DeriveLabel(999999)) + 10,
B_H_SCROLL_BAR_HEIGHT);
} }
virtual BSize MinSize() virtual BSize MinSize()
{ {
BString label(_GetLabel()); return fMinSize;
return BSize(StringWidth(label) + 10, B_H_SCROLL_BAR_HEIGHT);
} }
virtual BSize PreferredSize() virtual BSize PreferredSize()
@@ -685,13 +690,11 @@ public:
{ {
FillRect(updateRect, B_SOLID_LOW); FillRect(updateRect, B_SOLID_LOW);
BString label(_GetLabel());
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
BRect bounds(Bounds()); BRect bounds(Bounds());
float width = StringWidth(label); float width = StringWidth(fLabel);
BPoint offset; BPoint offset;
offset.x = bounds.left + (bounds.Width() - width) / 2.0f; offset.x = bounds.left + (bounds.Width() - width) / 2.0f;
@@ -699,32 +702,38 @@ public:
- (fontHeight.ascent + fontHeight.descent)) / 2.0f - (fontHeight.ascent + fontHeight.descent)) / 2.0f
+ fontHeight.ascent; + fontHeight.ascent;
DrawString(label, offset); DrawString(fLabel, offset);
} }
void SetItemCount(int32 count) void SetItemCount(int32 count)
{ {
if (count == fItemCount) if (count == fItemCount)
return; return;
BSize minSize = MinSize();
fItemCount = count; fItemCount = count;
if (minSize != MinSize()) fLabel = _DeriveLabel(fItemCount);
InvalidateLayout();
Invalidate(); Invalidate();
} }
private: private:
BString _GetLabel() const
/*! 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, " static BStringFormat format(B_TRANSLATE("{0, plural, "
"one{# item} other{# items}}")); "one{# item} other{# items}}"));
BString label; BString label;
format.Format(label, fItemCount); format.Format(label, count);
return label; return label;
} }
int32 fItemCount; int32 fItemCount;
BString fLabel;
BSize fMinSize;
}; };