Skip to content

Commit

Permalink
pw_metric: Make constructors constexpr
Browse files Browse the repository at this point in the history
This CL makes the following constructors constexpr:

- pw::metric::Group(Token)
- pw::metric::Metric(Token, float)
- pw::metric::Metric(Token, uint32_t)
- pw::metric::TypedMetric<float>(Token, float)
- pw::metric::TypedMetric<uint32_t>(Token, uint32_t)

Change-Id: I601d76cda0f5a03747df8282337da7afa94fe3db
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/172379
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Aaron Green <aarongreen@google.com>
  • Loading branch information
nopsledder authored and CQ Bot Account committed Sep 25, 2023
1 parent 5715233 commit 3cfe5d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 0 additions & 2 deletions pw_metric/metric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ void Metric::Dump(IntrusiveList<Metric>& metrics, int level) {
}
}

Group::Group(Token name) : name_(name) {}

Group::Group(Token name, IntrusiveList<Group>& groups) : name_(name) {
groups.push_front(*this);
}
Expand Down
10 changes: 5 additions & 5 deletions pw_metric/public/pw_metric/metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class Metric : public IntrusiveList<Metric>::Item {
void operator=(const Metric&) = delete;

protected:
Metric(Token name, float value)
constexpr Metric(Token name, float value)
: name_and_type_((name & kTokenMask) | kTypeFloat), float_(value) {}

Metric(Token name, uint32_t value)
constexpr Metric(Token name, uint32_t value)
: name_and_type_((name & kTokenMask) | kTypeInt), uint_(value) {}

Metric(Token name, float value, IntrusiveList<Metric>& metrics);
Expand Down Expand Up @@ -112,7 +112,7 @@ class TypedMetric;
template <>
class TypedMetric<float> : public Metric {
public:
TypedMetric(Token name, float value) : Metric(name, value) {}
constexpr TypedMetric(Token name, float value) : Metric(name, value) {}
TypedMetric(Token name, float value, IntrusiveList<Metric>& metrics)
: Metric(name, value, metrics) {}

Expand All @@ -129,7 +129,7 @@ class TypedMetric<float> : public Metric {
template <>
class TypedMetric<uint32_t> : public Metric {
public:
TypedMetric(Token name, uint32_t value) : Metric(name, value) {}
constexpr TypedMetric(Token name, uint32_t value) : Metric(name, value) {}
TypedMetric(Token name, uint32_t value, IntrusiveList<Metric>& metrics)
: Metric(name, value, metrics) {}

Expand All @@ -148,7 +148,7 @@ class TypedMetric<uint32_t> : public Metric {
// Size: 16 bytes/128 bits - next, name, metrics, children.
class Group : public IntrusiveList<Group>::Item {
public:
Group(Token name);
constexpr Group(Token name) : name_(name) {}
Group(Token name, IntrusiveList<Group>& groups);

Token name() const { return name_; }
Expand Down

0 comments on commit 3cfe5d0

Please sign in to comment.