summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgeorgesak <georgesak@chromium.org>2014-12-03 17:55:11 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-04 01:55:33 +0000
commit7d527ea37727f05e36ec15744d2ce7decac37ffb (patch)
treeae003786c392d674b5ce4906e062ff63cd684ed2
parentfc6eee783a9ddf06c7a66029b35c6275c2ddbe24 (diff)
downloadchromium_src-7d527ea37727f05e36ec15744d2ce7decac37ffb.zip
chromium_src-7d527ea37727f05e36ec15744d2ce7decac37ffb.tar.gz
chromium_src-7d527ea37727f05e36ec15744d2ce7decac37ffb.tar.bz2
Various optimizations to reduce the number of temporary allocations
(depends on CL753603002). - Replaced StringPrintf with multiple appends for improved performance. - Reduced the number of temporary string allocations. - Changed the algorithm by which an IDR is searched, using a standard linear search (removed the temporary set that was created). BUG= Review URL: https://codereview.chromium.org/747013003 Cr-Commit-Position: refs/heads/master@{#306743}
-rw-r--r--chrome/browser/extensions/api/font_settings/font_settings_api.cc17
-rw-r--r--chrome/browser/themes/browser_theme_pack.cc14
-rw-r--r--chrome/browser/themes/browser_theme_pack.h6
-rw-r--r--chrome/browser/themes/theme_properties.cc8
-rw-r--r--chrome/browser/themes/theme_properties.h3
-rw-r--r--chrome/browser/themes/theme_service.cc9
-rw-r--r--chrome/browser/ui/prefs/prefs_tab_helper.cc9
-rw-r--r--chrome/browser/ui/webui/theme_source.cc5
8 files changed, 27 insertions, 44 deletions
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 cf01a958..09d618d 100644
--- a/chrome/browser/extensions/api/font_settings/font_settings_api.cc
+++ b/chrome/browser/extensions/api/font_settings/font_settings_api.cc
@@ -86,8 +86,7 @@ void RegisterFontFamilyMapObserver(
const PrefChangeRegistrar::NamedChangeCallback& callback) {
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);
- registrar->Add(pref_name.c_str(), callback);
+ registrar->Add(base::StringPrintf("%s.%s", map_name, script), callback);
}
}
@@ -156,7 +155,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 +186,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 +234,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 +251,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 +287,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;
diff --git a/chrome/browser/themes/browser_theme_pack.cc b/chrome/browser/themes/browser_theme_pack.cc
index fe2f645..ab80732 100644
--- a/chrome/browser/themes/browser_theme_pack.cc
+++ b/chrome/browser/themes/browser_theme_pack.cc
@@ -779,18 +779,18 @@ scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack(
}
// static
-void BrowserThemePack::GetThemeableImageIDRs(std::set<int>* result) {
- if (!result)
- return;
-
- result->clear();
+bool BrowserThemePack::IsPersistentImageID(int id) {
for (size_t i = 0; i < kPersistingImagesLength; ++i)
- result->insert(kPersistingImages[i].idr_id);
+ if (kPersistingImages[i].idr_id == id)
+ return true;
#if defined(USE_ASH) && !defined(OS_CHROMEOS)
for (size_t i = 0; i < kPersistingImagesDesktopAuraLength; ++i)
- result->insert(kPersistingImagesDesktopAura[i].idr_id);
+ if (kPersistingImagesDesktopAura[i].idr_id == id)
+ return true;
#endif
+
+ return false;
}
bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const {
diff --git a/chrome/browser/themes/browser_theme_pack.h b/chrome/browser/themes/browser_theme_pack.h
index effba56..7ad69c9 100644
--- a/chrome/browser/themes/browser_theme_pack.h
+++ b/chrome/browser/themes/browser_theme_pack.h
@@ -67,9 +67,9 @@ class BrowserThemePack : public CustomThemeSupplier {
static scoped_refptr<BrowserThemePack> BuildFromDataPack(
const base::FilePath& path, const std::string& expected_id);
- // Returns the set of image IDRs which can be overwritten by a user provided
- // theme.
- static void GetThemeableImageIDRs(std::set<int>* result);
+ // Returns whether the specified identifier is one of the images we persist
+ // in the data pack.
+ static bool IsPersistentImageID(int id);
// Builds a data pack on disk at |path| for future quick loading by
// BuildFromDataPack(). Often (but not always) called from the file thread;
diff --git a/chrome/browser/themes/theme_properties.cc b/chrome/browser/themes/theme_properties.cc
index caafb1c..1da2ec8 100644
--- a/chrome/browser/themes/theme_properties.cc
+++ b/chrome/browser/themes/theme_properties.cc
@@ -201,14 +201,6 @@ std::string ThemeProperties::TilingToString(int tiling) {
}
// static
-bool ThemeProperties::IsThemeableImage(int id) {
- // TODO(pkotwicz): Cache results to improve lookup speed.
- std::set<int> themeable_idrs;
- BrowserThemePack::GetThemeableImageIDRs(&themeable_idrs);
- return themeable_idrs.find(id) != themeable_idrs.end();
-}
-
-// static
const std::set<int>& ThemeProperties::GetTintableToolbarButtons() {
CR_DEFINE_STATIC_LOCAL(std::set<int>, button_set, ());
if (button_set.empty()) {
diff --git a/chrome/browser/themes/theme_properties.h b/chrome/browser/themes/theme_properties.h
index 3a34e8b..530315c 100644
--- a/chrome/browser/themes/theme_properties.h
+++ b/chrome/browser/themes/theme_properties.h
@@ -129,9 +129,6 @@ class ThemeProperties {
// generate a CSS value.
static std::string TilingToString(int tiling);
- // Returns true if the image is themeable.
- static bool IsThemeableImage(int resource_id);
-
// Returns the set of IDR_* resources that should be tinted.
// This method is not thread safe.
static const std::set<int>& GetTintableToolbarButtons();
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index 053cfb8..7b20d39 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -236,13 +236,8 @@ bool ThemeService::ShouldUseNativeFrame() const {
}
bool ThemeService::HasCustomImage(int id) const {
- if (!Properties::IsThemeableImage(id))
- return false;
-
- if (theme_supplier_.get())
- return theme_supplier_->HasCustomImage(id);
-
- return false;
+ return BrowserThemePack::IsPersistentImageID(id) &&
+ theme_supplier_ && theme_supplier_->HasCustomImage(id);
}
base::RefCountedMemory* ThemeService::GetRawData(
diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.cc b/chrome/browser/ui/prefs/prefs_tab_helper.cc
index 0eec3d8..5ef1419 100644
--- a/chrome/browser/ui/prefs/prefs_tab_helper.cc
+++ b/chrome/browser/ui/prefs/prefs_tab_helper.cc
@@ -131,12 +131,11 @@ void RegisterFontFamilyMapObserver(
PrefChangeRegistrar* registrar,
const char* map_name,
const PrefChangeRegistrar::NamedChangeCallback& obs) {
- bool result = StartsWithASCII(map_name, "webkit.webprefs.", true);
- DCHECK(result);
+ DCHECK(StartsWithASCII(map_name, "webkit.webprefs.", true));
+
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);
- registrar->Add(pref_name.c_str(), obs);
+ registrar->Add(base::StringPrintf("%s.%s", map_name, script), obs);
}
}
@@ -632,7 +631,7 @@ void PrefsTabHelper::OnFontFamilyPrefChanged(const std::string& pref_name) {
&generic_family,
&script)) {
PrefService* prefs = GetProfile()->GetPrefs();
- std::string pref_value = prefs->GetString(pref_name.c_str());
+ std::string pref_value = prefs->GetString(pref_name);
if (pref_value.empty()) {
WebPreferences web_prefs =
web_contents_->GetRenderViewHost()->GetWebkitPreferences();
diff --git a/chrome/browser/ui/webui/theme_source.cc b/chrome/browser/ui/webui/theme_source.cc
index 0c60f02..6d6cda6 100644
--- a/chrome/browser/ui/webui/theme_source.cc
+++ b/chrome/browser/ui/webui/theme_source.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resources_util.h"
#include "chrome/browser/search/instant_io_context.h"
+#include "chrome/browser/themes/browser_theme_pack.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
@@ -113,7 +114,7 @@ base::MessageLoop* ThemeSource::MessageLoopForRequestPath(
// If it's not a themeable image, we don't need to go to the UI thread.
int resource_id = ResourcesUtil::GetThemeResourceId(uncached_path);
- if (!ThemeProperties::IsThemeableImage(resource_id))
+ if (!BrowserThemePack::IsPersistentImageID(resource_id))
return NULL;
return content::URLDataSource::MessageLoopForRequestPath(path);
@@ -140,7 +141,7 @@ void ThemeSource::SendThemeBitmap(
float scale_factor) {
ui::ScaleFactor resource_scale_factor =
ui::GetSupportedScaleFactor(scale_factor);
- if (ThemeProperties::IsThemeableImage(resource_id)) {
+ if (BrowserThemePack::IsPersistentImageID(resource_id)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile_);
DCHECK(tp);