From 007b3f812fc9c989fb99d4a668d8bd9c7807ad81 Mon Sep 17 00:00:00 2001 From: "dcheng@chromium.org" Date: Tue, 9 Apr 2013 08:46:45 +0000 Subject: Rewrite std::string("") to std::string(), Linux edition. This patch was generated by running the empty_string clang tool across the Chromium Linux compilation database. Implicitly or explicitly constructing std::string() with a "" argument is inefficient as the caller needs to emit extra instructions to pass an argument, and the constructor needlessly copies a byte into internal storage. Rewriting these instances to simply call the default constructor appears to save ~14-18 kilobytes on an optimized release build. BUG=none Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=193020 Review URL: https://codereview.chromium.org/13145003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193040 0039d316-1c4b-4281-b951-d872f2087c98 --- base/metrics/field_trial.cc | 2 +- base/metrics/field_trial_unittest.cc | 4 ++-- base/metrics/statistics_recorder.cc | 2 +- base/metrics/stats_counters.cc | 2 +- base/metrics/stats_table.cc | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'base/metrics') diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index 4ab5ff9..1f4f9ae 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc @@ -318,7 +318,7 @@ std::string FieldTrialList::FindFullName(const std::string& name) { FieldTrial* field_trial = Find(name); if (field_trial) return field_trial->group_name(); - return ""; + return std::string(); } // static diff --git a/base/metrics/field_trial_unittest.cc b/base/metrics/field_trial_unittest.cc index 81c4f37..bb2c39f 100644 --- a/base/metrics/field_trial_unittest.cc +++ b/base/metrics/field_trial_unittest.cc @@ -86,7 +86,7 @@ TEST_F(FieldTrialTest, Registration) { EXPECT_EQ(name1, trial1->trial_name()); EXPECT_EQ("", trial1->group_name_internal()); - trial1->AppendGroup("", 7); + trial1->AppendGroup(std::string(), 7); EXPECT_EQ(trial1, FieldTrialList::Find(name1)); EXPECT_FALSE(FieldTrialList::Find(name2)); @@ -221,7 +221,7 @@ TEST_F(FieldTrialTest, OneWinner) { std::string winner_name; for (int i = 1; i <= group_count; ++i) { - int might_win = trial->AppendGroup("", 1); + int might_win = trial->AppendGroup(std::string(), 1); // Because we keep appending groups, we want to see if the last group that // was added has been assigned or not. diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc index f6174f3..13aeeb7 100644 --- a/base/metrics/statistics_recorder.cc +++ b/base/metrics/statistics_recorder.cc @@ -308,7 +308,7 @@ StatisticsRecorder::~StatisticsRecorder() { DCHECK(histograms_ && ranges_ && lock_); if (dump_on_exit_) { string output; - WriteGraph("", &output); + WriteGraph(std::string(), &output); DLOG(INFO) << output; } diff --git a/base/metrics/stats_counters.cc b/base/metrics/stats_counters.cc index f763220..12416d9 100644 --- a/base/metrics/stats_counters.cc +++ b/base/metrics/stats_counters.cc @@ -45,7 +45,7 @@ int* StatsCounter::GetPtr() { if (counter_id_ == -1) { counter_id_ = table->FindCounter(name_); if (table->GetSlot() == 0) { - if (!table->RegisterThread("")) { + if (!table->RegisterThread(std::string())) { // There is no room for this thread. This thread // cannot use counters. counter_id_ = 0; diff --git a/base/metrics/stats_table.cc b/base/metrics/stats_table.cc index dede1e4..9585863 100644 --- a/base/metrics/stats_table.cc +++ b/base/metrics/stats_table.cc @@ -431,8 +431,8 @@ int* StatsTable::FindLocation(const char* name) { // Get the slot for this thread. Try to register // it if none exists. int slot = table->GetSlot(); - if (!slot && !(slot = table->RegisterThread(""))) - return NULL; + if (!slot && !(slot = table->RegisterThread(std::string()))) + return NULL; // Find the counter id for the counter. std::string str_name(name); -- cgit v1.1