Commit d1d86a9d authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Views: don't unnecessarily create temp label when sizing LocationIconView

This change is a 15% resize speedup in a release build on my machine.

Bug: 850128
Change-Id: Icbcd79b7ea5a8a5f06fc20595f67092b8bd12c42
Reviewed-on: https://chromium-review.googlesource.com/1110700Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570903}
parent f07c2fc0
...@@ -104,9 +104,17 @@ bool LocationIconView::IsBubbleShowing() const { ...@@ -104,9 +104,17 @@ bool LocationIconView::IsBubbleShowing() const {
gfx::Size LocationIconView::GetMinimumSizeForLabelText( gfx::Size LocationIconView::GetMinimumSizeForLabelText(
const base::string16& text) const { const base::string16& text) const {
views::Label label(text, {font_list()}); int width = 0;
return GetMinimumSizeForPreferredSize( if (text == label()->text()) {
GetSizeForLabelWidth(label.GetPreferredSize().width())); // Optimize this common case by not creating a new label.
// GetPreferredSize is not dependent on the label's current
// width, so this returns the same value as the branch below.
width = label()->GetPreferredSize().width();
} else {
views::Label label(text, {font_list()});
width = label.GetPreferredSize().width();
}
return GetMinimumSizeForPreferredSize(GetSizeForLabelWidth(width));
} }
void LocationIconView::SetTextVisibility(bool should_show, void LocationIconView::SetTextVisibility(bool should_show,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment