From faa62b0d1e5ee6343cd67c7a2f24045e727d56ff Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 16:15:27 -0400 Subject: [PATCH 1/3] telemetry: Default copy/move constructors and assignment operators This provides the equivalent behavior, but without as much boilerplate. While we're at it, explicitly default the move constructor, since we have a move-assignment operator defined. --- src/common/telemetry.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 3694c76f2..f96bab4f9 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -58,21 +58,11 @@ public: Field(FieldType type, std::string name, T&& value) : name(std::move(name)), type(type), value(std::move(value)) {} - Field(const Field& other) : Field(other.type, other.name, other.value) {} + Field(const Field& other) = default; + Field& operator=(const Field& other) = default; - Field& operator=(const Field& other) { - type = other.type; - name = other.name; - value = other.value; - return *this; - } - - Field& operator=(Field&& other) { - type = other.type; - name = std::move(other.name); - value = std::move(other.value); - return *this; - } + Field(Field&&) = default; + Field& operator=(Field&& other) = default; void Accept(VisitorInterface& visitor) const override; From 3244042c4c6c16249e0d21a6e6538615d26079c2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 16:17:37 -0400 Subject: [PATCH 2/3] telemetry: Make operator== and operator!= const member functions of Field These operators don't modify internal class state, so they can be made const member functions. While we're at it, drop the unnecessary inline keywords. Member functions that are defined in the class declaration are already inline by default. --- src/common/telemetry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/telemetry.h b/src/common/telemetry.h index f96bab4f9..701f5ed74 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -84,11 +84,11 @@ public: return value; } - inline bool operator==(const Field& other) { + bool operator==(const Field& other) const { return (type == other.type) && (name == other.name) && (value == other.value); } - inline bool operator!=(const Field& other) { + bool operator!=(const Field& other) const { return !(*this == other); } From 0a8563fb79ab690815264de55d8879ed8cdf51e7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 16:18:30 -0400 Subject: [PATCH 3/3] telemetry: Remove unnecessary Field constructor We can just take the value parameter by value which allows both moving into it, and copies at the same time, depending on the calling code. --- src/common/telemetry.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 701f5ed74..9439edde4 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -52,10 +52,7 @@ public: template class Field : public FieldInterface { public: - Field(FieldType type, std::string name, const T& value) - : name(std::move(name)), type(type), value(value) {} - - Field(FieldType type, std::string name, T&& value) + Field(FieldType type, std::string name, T value) : name(std::move(name)), type(type), value(std::move(value)) {} Field(const Field& other) = default;