Index: dbus/dbus_statistics.cc |
diff --git a/dbus/dbus_statistics.cc b/dbus/dbus_statistics.cc |
index 4bcf7fbaa4a5a39c97d679622c9b82ee24282460..e4c7d2385e4875aa0b714f9137f17f125f74d542 100644 |
--- a/dbus/dbus_statistics.cc |
+++ b/dbus/dbus_statistics.cc |
@@ -4,12 +4,13 @@ |
#include "dbus/dbus_statistics.h" |
+#include <map> |
#include <memory> |
-#include <set> |
+#include <tuple> |
#include "base/logging.h" |
#include "base/macros.h" |
-#include "base/stl_util.h" |
+#include "base/memory/ptr_util.h" |
#include "base/strings/stringprintf.h" |
#include "base/threading/platform_thread.h" |
#include "base/time/time.h" |
@@ -38,23 +39,16 @@ struct Stat { |
int received_signals; |
int sent_blocking_method_calls; |
- bool Compare(const Stat& other) const { |
- if (service != other.service) |
- return service < other.service; |
- if (interface != other.interface) |
- return interface < other.interface; |
- return method < other.method; |
- } |
- |
struct PtrCompare { |
bool operator()(Stat* lhs, Stat* rhs) const { |
DCHECK(lhs && rhs); |
- return lhs->Compare(*rhs); |
+ return std::tie(lhs->service, lhs->interface, lhs->method) < |
+ std::tie(rhs->service, rhs->interface, rhs->method); |
} |
}; |
}; |
-typedef std::set<Stat*, Stat::PtrCompare> StatSet; |
+using StatSet = std::map<Stat*, std::unique_ptr<Stat>, Stat::PtrCompare>; |
satorux1
2016/10/11 01:29:58
why was it changed from set to map?
if it's a map
Avi (use Gerrit)
2016/10/11 16:31:46
In doing the conversions I've been switching becau
|
//------------------------------------------------------------------------------ |
// DBusStatistics |
@@ -69,7 +63,6 @@ class DBusStatistics { |
~DBusStatistics() { |
DCHECK_EQ(origin_thread_id_, base::PlatformThread::CurrentId()); |
- base::STLDeleteContainerPointers(stats_.begin(), stats_.end()); |
} |
// Enum to specify which field in Stat to increment in AddStat |
@@ -108,14 +101,16 @@ class DBusStatistics { |
const std::string& method, |
bool add_stat) { |
DCHECK_EQ(origin_thread_id_, base::PlatformThread::CurrentId()); |
- std::unique_ptr<Stat> stat(new Stat(service, interface, method)); |
- StatSet::iterator found = stats_.find(stat.get()); |
+ std::unique_ptr<Stat> stat = |
+ base::MakeUnique<Stat>(service, interface, method); |
+ auto found = stats_.find(stat.get()); |
if (found != stats_.end()) |
- return *found; |
+ return found->first; |
if (!add_stat) |
- return NULL; |
- found = stats_.insert(stat.release()).first; |
- return *found; |
+ return nullptr; |
+ Stat* stat_ptr = stat.get(); |
+ stats_[stat_ptr] = std::move(stat); |
+ return stat_ptr; |
} |
StatSet& stats() { return stats_; } |
@@ -129,7 +124,7 @@ class DBusStatistics { |
DISALLOW_COPY_AND_ASSIGN(DBusStatistics); |
}; |
-DBusStatistics* g_dbus_statistics = NULL; |
+DBusStatistics* g_dbus_statistics = nullptr; |
} // namespace |
@@ -145,7 +140,7 @@ void Initialize() { |
void Shutdown() { |
delete g_dbus_statistics; |
- g_dbus_statistics = NULL; |
+ g_dbus_statistics = nullptr; |
} |
void AddSentMethodCall(const std::string& service, |
@@ -193,19 +188,20 @@ std::string GetAsString(ShowInString show, FormatString format) { |
std::string result; |
int sent = 0, received = 0, sent_blocking = 0; |
// Stats are stored in order by service, then interface, then method. |
- for (StatSet::const_iterator iter = stats.begin(); iter != stats.end(); ) { |
- StatSet::const_iterator cur_iter = iter; |
- StatSet::const_iterator next_iter = ++iter; |
- const Stat* stat = *cur_iter; |
+ for (auto iter = stats.begin(); iter != stats.end();) { |
+ auto cur_iter = iter; |
+ auto next_iter = ++iter; |
+ const Stat* stat = cur_iter->first; |
sent += stat->sent_method_calls; |
received += stat->received_signals; |
sent_blocking += stat->sent_blocking_method_calls; |
// If this is not the last stat, and if the next stat matches the current |
// stat, continue. |
if (next_iter != stats.end() && |
- (*next_iter)->service == stat->service && |
- (show < SHOW_INTERFACE || (*next_iter)->interface == stat->interface) && |
- (show < SHOW_METHOD || (*next_iter)->method == stat->method)) |
+ next_iter->first->service == stat->service && |
+ (show < SHOW_INTERFACE || |
+ next_iter->first->interface == stat->interface) && |
+ (show < SHOW_METHOD || next_iter->first->method == stat->method)) |
continue; |
if (!sent && !received && !sent_blocking) |