From 40b7050ac6702e0491336d6503029d12865bf9f9 Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Mon, 27 Aug 2018 10:55:07 +0200 Subject: [PATCH] Add copy and move constructors to RateStatistics. Bug: none Change-Id: I589a7f202ee1c4b8c06e8f44aa570c47d066ab72 Reviewed-on: https://webrtc-review.googlesource.com/95647 Commit-Queue: Sergey Silkin Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#24445} --- rtc_base/BUILD.gn | 1 + rtc_base/rate_statistics.cc | 16 ++++++++++++++++ rtc_base/rate_statistics.h | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index e8a72c7824..7a03b3bfb5 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -444,6 +444,7 @@ rtc_source_set("rtc_base_approved_generic") { deps += [ "..:webrtc_common", "../api:array_view", + "//third_party/abseil-cpp/absl/memory:memory", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/rtc_base/rate_statistics.cc b/rtc_base/rate_statistics.cc index 9b1ff8fc9a..bb506aa7f4 100644 --- a/rtc_base/rate_statistics.cc +++ b/rtc_base/rate_statistics.cc @@ -12,6 +12,7 @@ #include +#include "absl/memory/memory.h" #include "rtc_base/checks.h" namespace webrtc { @@ -26,6 +27,21 @@ RateStatistics::RateStatistics(int64_t window_size_ms, float scale) max_window_size_ms_(window_size_ms), current_window_size_ms_(max_window_size_ms_) {} +RateStatistics::RateStatistics(const RateStatistics& other) + : accumulated_count_(other.accumulated_count_), + num_samples_(other.num_samples_), + oldest_time_(other.oldest_time_), + oldest_index_(other.oldest_index_), + scale_(other.scale_), + max_window_size_ms_(other.max_window_size_ms_), + current_window_size_ms_(other.current_window_size_ms_) { + buckets_ = absl::make_unique(other.max_window_size_ms_); + std::copy(other.buckets_.get(), + other.buckets_.get() + other.max_window_size_ms_, buckets_.get()); +} + +RateStatistics::RateStatistics(RateStatistics&& other) = default; + RateStatistics::~RateStatistics() {} void RateStatistics::Reset() { diff --git a/rtc_base/rate_statistics.h b/rtc_base/rate_statistics.h index 89bfddfa55..68035c9a68 100644 --- a/rtc_base/rate_statistics.h +++ b/rtc_base/rate_statistics.h @@ -27,6 +27,11 @@ class RateStatistics { // scale = coefficient to convert counts/ms to desired unit // ex: kBpsScale (8000) for bits/s if count represents bytes. RateStatistics(int64_t max_window_size_ms, float scale); + + RateStatistics(const RateStatistics& other); + + RateStatistics(RateStatistics&& other); + ~RateStatistics(); // Reset instance to original state.