Chromium Code Reviews| Index: ui/gfx/font_list.cc |
| diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc |
| index e977882bed90ea4d96a30e8e4859e4423839ca8e..a9856df1bca9cbb37ea27fcb3bc31f23de947bd7 100644 |
| --- a/ui/gfx/font_list.cc |
| +++ b/ui/gfx/font_list.cc |
| @@ -18,6 +18,11 @@ namespace { |
| base::LazyInstance<std::string>::Leaky g_default_font_description = |
| LAZY_INSTANCE_INITIALIZER; |
| +// The default instance of gfx::FontList, whose metrics are pre-calculated. |
| +// The default ctor of gfx::FontList copies the metrics so it won't need to |
| +// scan the whole font list to calculate the metrics. |
| +const gfx::FontList* g_default_font_list = NULL; |
| + |
| // Parses font description into |font_names|, |font_style| and |font_size|. |
| void ParseFontDescriptionString(const std::string& font_description_string, |
| std::vector<std::string>* font_names, |
| @@ -85,9 +90,23 @@ FontList::FontList() |
| DCHECK(!(g_default_font_description == NULL)) // != is not overloaded. |
| << "SetDefaultFontDescription has not been called."; |
| - font_description_string_ = g_default_font_description.Get(); |
| - if (font_description_string_.empty()) |
| - fonts_.push_back(Font()); |
| + // Allocate the global instance of FontList for |g_default_font_list| without |
| + // calling the default ctor. |
| + static FontList default_font_list((Font())); |
| + |
| + if (!g_default_font_list) { |
| + default_font_list = g_default_font_description.Get().empty() ? |
| + FontList(Font()) : FontList(g_default_font_description.Get()); |
| + // Pre-calculate the metrics. |
| + if (default_font_list.GetPrimaryFont().platform_font()) { |
|
Alexei Svitkine (slow)
2014/01/09 20:58:13
Can you add a comment explaining this if statement
Yuki
2014/01/10 04:57:10
Added a comment.
Android and Linux + Ozone don't
|
| + default_font_list.CacheCommonFontHeightAndBaseline(); |
| + default_font_list.CacheFontStyleAndSize(); |
| + } |
| + g_default_font_list = &default_font_list; |
| + } |
| + |
| + // Copy the default font list specification and its pre-calculated metrics. |
| + *this = *g_default_font_list; |
| } |
| FontList::FontList(const std::string& font_description_string) |
| @@ -150,6 +169,7 @@ void FontList::SetDefaultFontDescription(const std::string& font_description) { |
| EndsWith(font_description, "px", true)); |
| g_default_font_description.Get() = font_description; |
| + g_default_font_list = NULL; |
| } |
| FontList FontList::DeriveFontList(int font_style) const { |