From 1ac0bea35fd7eaeb4c4e57216ae9f7690a1a5702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Fri, 12 Jan 2024 12:53:23 +0100 Subject: [PATCH] [Stats] Delete unused method RTCStats::Members(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For iteration of metrics, use RTCStats::Attributes() instead. In a follow-up CL, RTCStatsMember types will be replaced by absl::optional and RTCStatsMemberInterface and friends will be deleted. Bug: webrtc:15164 Change-Id: Ifca1d36abac3068abd299df49da36cacea1898fa Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/334202 Commit-Queue: Henrik Boström Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#41534} --- api/stats/rtc_stats.h | 52 +++++++++---------------------------------- stats/rtc_stats.cc | 12 ---------- 2 files changed, 11 insertions(+), 53 deletions(-) diff --git a/api/stats/rtc_stats.h b/api/stats/rtc_stats.h index f563f2e022..636dd375c0 100644 --- a/api/stats/rtc_stats.h +++ b/api/stats/rtc_stats.h @@ -39,8 +39,8 @@ namespace webrtc { // Use the `WEBRTC_RTCSTATS_IMPL` macro when implementing subclasses, see macro // for details. // -// Derived classes list their dictionary members, RTCStatsMember, as public -// fields, allowing the following: +// Derived classes list their dictionary attributes (RTCStatsMember to soon +// be replaced by absl::optional) as public fields, allowing the following: // // RTCFooStats foo("fooId", Timestamp::Micros(GetCurrentTime())); // foo.bar = 42; @@ -48,10 +48,11 @@ namespace webrtc { // foo.baz->push_back("hello world"); // uint32_t x = *foo.bar; // -// Pointers to all the members are available with `Members`, allowing iteration: +// Pointers to all the attributes are available with `Attributes()`, allowing +// iteration: // -// for (const RTCStatsMemberInterface* member : foo.Members()) { -// printf("%s = %s\n", member->name(), member->ValueToString().c_str()); +// for (const auto& attribute : foo.Attributes()) { +// printf("%s = %s\n", attribute.name(), attribute.ValueToString().c_str()); // } class RTC_EXPORT RTCStats { public: @@ -84,18 +85,14 @@ class RTC_EXPORT RTCStats { } RTC_CHECK_NOTREACHED(); } - // Returns Attributes() as `RTCStatsMemberInterface` pointers. - // TODO(https://crbug.com/webrtc/15164): Update callers to use Attributes() - // instead and delete this method as well as the RTCStatsMemberInterface. - std::vector Members() const; // Checks if the two stats objects are of the same type and have the same - // member values. Timestamps are not compared. These operators are exposed for - // testing. + // attribute values. Timestamps are not compared. These operators are exposed + // for testing. bool operator==(const RTCStats& other) const; bool operator!=(const RTCStats& other) const; // Creates a JSON readable string representation of the stats - // object, listing all of its members (names and values). + // object, listing all of its attributes (names and values). std::string ToJson() const; // Downcasts the stats object to an `RTCStats` subclass `T`. DCHECKs that the @@ -112,13 +109,6 @@ class RTC_EXPORT RTCStats { std::string const id_; Timestamp timestamp_; - - // Because Members() return a raw pointers we need to cache attributes to - // ensure the pointers are still valid after the method has returned. Mutable - // to allow lazy instantiation the first time the method is called. - // TODO(https://crbug.com/webrtc/15164): Migrate all uses of Members() to - // Attributes() and delete Members() and `cached_attributes_`. - mutable std::vector cached_attributes_; }; // All `RTCStats` classes should use these macros. @@ -127,9 +117,8 @@ class RTC_EXPORT RTCStats { // // These macros declare (in _DECL) and define (in _IMPL) the static `kType` and // overrides methods as required by subclasses of `RTCStats`: `copy`, `type` and -// `MembersOfThisObjectAndAncestors`. The |...| argument is a list of addresses -// to each member defined in the implementing class. The list must have at least -// one member. +// `AttributesImpl`. The |...| argument is a list of addresses to each attribute +// defined in the implementing class. The list must have at least one attribute. // // (Since class names need to be known to implement these methods this cannot be // part of the base `RTCStats`. While these methods could be implemented using @@ -197,25 +186,6 @@ class RTC_EXPORT RTCStats { return attributes; \ } -// A version of WEBRTC_RTCSTATS_IMPL() where "..." is omitted, used to avoid a -// compile error on windows. This is used if the stats dictionary does not -// declare any members of its own (but perhaps its parent dictionary does). -#define WEBRTC_RTCSTATS_IMPL_NO_MEMBERS(this_class, parent_class, type_str) \ - const char this_class::kType[] = type_str; \ - \ - std::unique_ptr this_class::copy() const { \ - return std::make_unique(*this); \ - } \ - \ - const char* this_class::type() const { \ - return this_class::kType; \ - } \ - \ - std::vector this_class::AttributesImpl( \ - size_t additional_capacity) const { \ - return parent_class::AttributesImpl(0); \ - } - } // namespace webrtc #endif // API_STATS_RTC_STATS_H_ diff --git a/stats/rtc_stats.cc b/stats/rtc_stats.cc index e6a1854d98..ea87379b95 100644 --- a/stats/rtc_stats.cc +++ b/stats/rtc_stats.cc @@ -65,18 +65,6 @@ std::string RTCStats::ToJson() const { return sb.Release(); } -std::vector RTCStats::Members() const { - if (cached_attributes_.empty()) { - cached_attributes_ = Attributes(); - } - std::vector members; - members.reserve(cached_attributes_.size()); - for (const auto& attribute : cached_attributes_) { - members.push_back(&attribute); - } - return members; -} - std::vector RTCStats::Attributes() const { return AttributesImpl(0); }