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

Unified Diff: webrtc/system_wrappers/source/metrics_default.cc

Issue 2268323002: Use swap instead of copy in RtcHistogram::GetAndReset. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: remove Reset change Created 4 years, 1 month 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 | webrtc/system_wrappers/source/metrics_default_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/system_wrappers/source/metrics_default.cc
diff --git a/webrtc/system_wrappers/source/metrics_default.cc b/webrtc/system_wrappers/source/metrics_default.cc
index 8ee10bacbc9e974484177d1b52a2c97205c82d38..d7d24fa50dab0e9e33aa8f8aadd3ac32b0f63bd3 100644
--- a/webrtc/system_wrappers/source/metrics_default.cc
+++ b/webrtc/system_wrappers/source/metrics_default.cc
@@ -9,6 +9,8 @@
#include "webrtc/system_wrappers/include/metrics_default.h"
+#include <algorithm>
+
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/system_wrappers/include/metrics.h"
@@ -34,10 +36,8 @@ class RtcHistogram {
}
void Add(int sample) {
- if (sample < min_)
- sample = min_ - 1; // Underflow bucket.
- if (sample > max_)
- sample = max_;
+ sample = std::min(sample, max_);
+ sample = std::max(sample, min_ - 1); // Underflow bucket.
rtc::CritScope cs(&crit_);
if (info_.samples.size() == kMaxSampleMapSize &&
@@ -55,8 +55,9 @@ class RtcHistogram {
SampleInfo* copy =
new SampleInfo(info_.name, info_.min, info_.max, info_.bucket_count);
- copy->samples = info_.samples;
- info_.samples.clear();
+
+ std::swap(info_.samples, copy->samples);
stefan-webrtc 2016/11/28 15:15:55 Should we clear info_.samples after this?
åsapersson 2016/11/29 14:22:21 copy->samples has an empty map before the swap.
stefan-webrtc 2016/11/29 16:15:53 Acknowledged.
+
return std::unique_ptr<SampleInfo>(copy);
}
« no previous file with comments | « no previous file | webrtc/system_wrappers/source/metrics_default_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698