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

Unified Diff: base/metrics/statistics_recorder.cc

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: rebased Created 3 years, 4 months 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 | « base/metrics/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.cc
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index 634f7b4c9519e07f36ef5621c1432c459413ea00..e403e524f24e6df27f9565f12dace3fcf4487e63 100644
--- a/base/metrics/statistics_recorder.cc
+++ b/base/metrics/statistics_recorder.cc
@@ -93,12 +93,13 @@ HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate(
// twice |if (!histograms_)|.
ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
} else {
- const std::string& name = histogram->histogram_name();
- HistogramMap::iterator it = histograms_->find(name);
+ const char* name = histogram->histogram_name();
+ StringPiece name_piece = name;
+ HistogramMap::iterator it = histograms_->find(name_piece);
if (histograms_->end() == it) {
// The StringKey references the name within |histogram| rather than
// making a copy.
- (*histograms_)[name] = histogram;
+ (*histograms_)[name_piece] = histogram;
ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
// If there are callbacks for this histogram, we set the kCallbackExists
// flag.
@@ -115,8 +116,9 @@ HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate(
histogram_to_return = histogram;
} else {
// We already have one histogram with this name.
- DCHECK_EQ(histogram->histogram_name(),
- it->second->histogram_name()) << "hash collision";
+ DCHECK_EQ(StringPiece(histogram->histogram_name()),
+ StringPiece(it->second->histogram_name()))
+ << "hash collision";
histogram_to_return = it->second;
histogram_to_delete = histogram;
}
@@ -329,8 +331,11 @@ void StatisticsRecorder::GetSnapshot(const std::string& query,
if (!histograms_)
return;
+ // Need a c-string query for comparisons against c-string histogram name.
+ const char* query_string = query.c_str();
+
for (const auto& entry : *histograms_) {
- if (entry.second->histogram_name().find(query) != std::string::npos)
+ if (strstr(entry.second->histogram_name(), query_string) != nullptr)
snapshot->push_back(entry.second);
}
}
« no previous file with comments | « base/metrics/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698