From 165daf264ed5a09e2e783191a89500ccae65a5d5 Mon Sep 17 00:00:00 2001 From: "asvitkine@chromium.org" Date: Fri, 3 Feb 2012 20:09:28 +0000 Subject: Optimize PlatformFontWin::GetFontSize(). Cache the value on HFontRef() instead of querying it each time from Windows APIs. BUG=105550 TEST=Existing unit tests. Review URL: http://codereview.chromium.org/9314049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120381 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/gfx/platform_font_win.cc | 7 +++---- ui/gfx/platform_font_win.h | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/gfx/platform_font_win.cc b/ui/gfx/platform_font_win.cc index b188677..1cca192 100644 --- a/ui/gfx/platform_font_win.cc +++ b/ui/gfx/platform_font_win.cc @@ -114,10 +114,7 @@ std::string PlatformFontWin::GetFontName() const { } int PlatformFontWin::GetFontSize() const { - LOGFONT font_info; - GetObject(font_ref_->hfont(), sizeof(LOGFONT), &font_info); - DCHECK_LT(font_info.lfHeight, 0); - return -font_info.lfHeight; + return font_ref_->font_size(); } NativeFont PlatformFontWin::GetNativeFont() const { @@ -217,6 +214,8 @@ PlatformFontWin::HFontRef::HFontRef(HFONT hfont, LOGFONT font_info; GetObject(hfont_, sizeof(LOGFONT), &font_info); font_name_ = UTF16ToUTF8(string16(font_info.lfFaceName)); + DCHECK_LT(font_info.lfHeight, 0); + font_size_ = -font_info.lfHeight; } PlatformFontWin::HFontRef::~HFontRef() { diff --git a/ui/gfx/platform_font_win.h b/ui/gfx/platform_font_win.h index 17178de..ce23105 100644 --- a/ui/gfx/platform_font_win.h +++ b/ui/gfx/platform_font_win.h @@ -82,6 +82,7 @@ class UI_EXPORT PlatformFontWin : public PlatformFont { int style() const { return style_; } int dlu_base_x() const { return dlu_base_x_; } const std::string& font_name() const { return font_name_; } + int font_size() const { return font_size_; } private: friend class base::RefCounted; @@ -96,6 +97,7 @@ class UI_EXPORT PlatformFontWin : public PlatformFont { // Constants used in converting dialog units to pixels. const int dlu_base_x_; std::string font_name_; + int font_size_; DISALLOW_COPY_AND_ASSIGN(HFontRef); }; -- cgit v1.1