Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: chrome/browser/extensions/api/font_settings/font_settings_api.cc

Issue 747013003: Various optimizations to reduce the number of temporary allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restored StringPrintf. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/themes/browser_theme_pack.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/font_settings/font_settings_api.cc
diff --git a/chrome/browser/extensions/api/font_settings/font_settings_api.cc b/chrome/browser/extensions/api/font_settings/font_settings_api.cc
index cf01a958e33df9ba0d82949357627cf7e80edca3..5a1e90fbe64ff0d8e03d8cba15b36a9c05211a2a 100644
--- a/chrome/browser/extensions/api/font_settings/font_settings_api.cc
+++ b/chrome/browser/extensions/api/font_settings/font_settings_api.cc
@@ -61,8 +61,8 @@ std::string GetFontNamePrefPath(fonts::GenericFamily generic_family_enum,
script = prefs::kWebKitCommonScript;
std::string generic_family = fonts::ToString(generic_family_enum);
return base::StringPrintf(kWebKitFontPrefFormat,
- generic_family.c_str(),
- script.c_str());
+ generic_family,
+ script);
}
// Returns the localized name of a font so that it can be matched within the
@@ -84,10 +84,14 @@ void RegisterFontFamilyMapObserver(
PrefChangeRegistrar* registrar,
const char* map_name,
const PrefChangeRegistrar::NamedChangeCallback& callback) {
+ std::string pref_name;
+ pref_name.reserve(512); // Reduces number of grows.
for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
- std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
Nico 2014/12/03 20:34:34 doesn't look restored?
- registrar->Add(pref_name.c_str(), callback);
+ pref_name.assign(map_name);
+ pref_name.append(1, '.');
+ pref_name.append(script);
+ registrar->Add(pref_name, callback);
}
}
@@ -109,21 +113,21 @@ FontSettingsEventRouter::FontSettingsEventRouter(
PrefChangeRegistrar::NamedChangeCallback callback =
base::Bind(&FontSettingsEventRouter::OnFontFamilyMapPrefChanged,
- base::Unretained(this));
- RegisterFontFamilyMapObserver(&registrar_,
- prefs::kWebKitStandardFontFamilyMap, callback);
- RegisterFontFamilyMapObserver(&registrar_,
- prefs::kWebKitSerifFontFamilyMap, callback);
- RegisterFontFamilyMapObserver(&registrar_,
- prefs::kWebKitSansSerifFontFamilyMap, callback);
- RegisterFontFamilyMapObserver(&registrar_,
- prefs::kWebKitFixedFontFamilyMap, callback);
- RegisterFontFamilyMapObserver(&registrar_,
- prefs::kWebKitCursiveFontFamilyMap, callback);
- RegisterFontFamilyMapObserver(&registrar_,
- prefs::kWebKitFantasyFontFamilyMap, callback);
- RegisterFontFamilyMapObserver(&registrar_,
- prefs::kWebKitPictographFontFamilyMap,
+ base::Unretained(this));
+ RegisterFontFamilyMapObserver(&registrar_,
+ prefs::kWebKitStandardFontFamilyMap, callback);
+ RegisterFontFamilyMapObserver(&registrar_,
+ prefs::kWebKitSerifFontFamilyMap, callback);
+ RegisterFontFamilyMapObserver(&registrar_,
+ prefs::kWebKitSansSerifFontFamilyMap, callback);
+ RegisterFontFamilyMapObserver(&registrar_,
+ prefs::kWebKitFixedFontFamilyMap, callback);
+ RegisterFontFamilyMapObserver(&registrar_,
+ prefs::kWebKitCursiveFontFamilyMap, callback);
+ RegisterFontFamilyMapObserver(&registrar_,
+ prefs::kWebKitFantasyFontFamilyMap, callback);
+ RegisterFontFamilyMapObserver(&registrar_,
+ prefs::kWebKitPictographFontFamilyMap,
callback);
}
@@ -156,7 +160,7 @@ void FontSettingsEventRouter::OnFontNamePrefChanged(
const std::string& generic_family,
const std::string& script) {
const PrefService::Preference* pref = registrar_.prefs()->FindPreference(
- pref_name.c_str());
+ pref_name);
CHECK(pref);
std::string font_name;
@@ -187,7 +191,7 @@ void FontSettingsEventRouter::OnFontPrefChanged(
const std::string& key,
const std::string& pref_name) {
const PrefService::Preference* pref = registrar_.prefs()->FindPreference(
- pref_name.c_str());
+ pref_name);
CHECK(pref);
base::ListValue args;
@@ -235,10 +239,10 @@ bool FontSettingsClearFontFunction::RunSync() {
// Ensure |pref_path| really is for a registered per-script font pref.
EXTENSION_FUNCTION_VALIDATE(
- GetProfile()->GetPrefs()->FindPreference(pref_path.c_str()));
+ GetProfile()->GetPrefs()->FindPreference(pref_path));
PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref(
- extension_id(), pref_path.c_str(), kExtensionPrefsScopeRegular);
+ extension_id(), pref_path, kExtensionPrefsScopeRegular);
return true;
}
@@ -252,7 +256,7 @@ bool FontSettingsGetFontFunction::RunSync() {
PrefService* prefs = GetProfile()->GetPrefs();
const PrefService::Preference* pref =
- prefs->FindPreference(pref_path.c_str());
+ prefs->FindPreference(pref_path);
std::string font_name;
EXTENSION_FUNCTION_VALIDATE(
@@ -288,11 +292,11 @@ bool FontSettingsSetFontFunction::RunSync() {
// Ensure |pref_path| really is for a registered font pref.
EXTENSION_FUNCTION_VALIDATE(
- GetProfile()->GetPrefs()->FindPreference(pref_path.c_str()));
+ GetProfile()->GetPrefs()->FindPreference(pref_path));
PreferenceAPI::Get(GetProfile())->SetExtensionControlledPref(
extension_id(),
- pref_path.c_str(),
+ pref_path,
kExtensionPrefsScopeRegular,
new base::StringValue(params->details.font_id));
return true;
« no previous file with comments | « no previous file | chrome/browser/themes/browser_theme_pack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698