From 4a11fab2b18ef8585bcfc6e914021e8587843cbf Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Tue, 5 Oct 2021 13:20:10 +0800 Subject: [PATCH] Add constexpr to Sample class functions --- src/base/bittorrent/speedmonitor.h | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/base/bittorrent/speedmonitor.h b/src/base/bittorrent/speedmonitor.h index 86ececd0b..6bb7c97c9 100644 --- a/src/base/bittorrent/speedmonitor.h +++ b/src/base/bittorrent/speedmonitor.h @@ -38,34 +38,30 @@ template struct Sample { - Sample() - : download() - , upload() - { - } + constexpr Sample() = default; - Sample(T dl, T ul) - : download(dl) - , upload(ul) + constexpr Sample(const T dl, const T ul) + : download {dl} + , upload {ul} { } - Sample &operator+=(const Sample &other) + constexpr Sample &operator+=(const Sample &other) { download += other.download; - upload += other.upload; + upload += other.upload; return *this; } - Sample &operator-=(const Sample &other) + constexpr Sample &operator-=(const Sample &other) { download -= other.download; - upload -= other.upload; + upload -= other.upload; return *this; } - T download; - T upload; + T download {}; + T upload {}; }; typedef Sample SpeedSample;