From: Remi Gacogne Date: Wed, 23 Sep 2020 08:29:26 +0000 (+0200) Subject: More DTime cleanups, as suggested by Otto during review X-Git-Tag: auth-4.4.0-alpha1~12^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0833d0cf666e70e8329e68a1669a3d3d39814b5;p=thirdparty%2Fpdns.git More DTime cleanups, as suggested by Otto during review --- diff --git a/pdns/misc.cc b/pdns/misc.cc index ef743a8e75..426a6d5559 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -440,17 +440,6 @@ string humanDuration(time_t passed) return ret.str(); } -DTime::DTime() -{ -// set(); // saves lots of gettimeofday calls - d_set.tv_sec=d_set.tv_usec=0; -} - -time_t DTime::time() -{ - return d_set.tv_sec; -} - const string unquotify(const string &item) { if(item.size()<2) diff --git a/pdns/misc.hh b/pdns/misc.hh index 488441912b..5d4f528e8b 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -191,10 +191,11 @@ On 32 bits systems this means that 2147 seconds is the longest time that can be class DTime { public: - DTime(); //!< Does not set the timer for you! Saves lots of gettimeofday() calls + //!< Does not set the timer for you! Saves lots of gettimeofday() calls + DTime() = default; DTime(const DTime &dt) = default; DTime & operator=(const DTime &dt) = default; - time_t time(); + inline time_t time() const; inline void set(); //!< Reset the timer inline int udiff(bool reset = true); //!< Return the number of microseconds since the timer was last set. @@ -206,23 +207,28 @@ public: { d_set=tv; } - struct timeval getTimeval() + struct timeval getTimeval() const { return d_set; } private: - struct timeval d_set; +struct timeval d_set{0, 0}; }; +inline time_t DTime::time() const +{ + return d_set.tv_sec; +} + inline void DTime::set() { - gettimeofday(&d_set,0); + gettimeofday(&d_set, nullptr); } inline int DTime::udiff(bool reset) { struct timeval now; - gettimeofday(&now,0); + gettimeofday(&now, nullptr); int ret=1000000*(now.tv_sec-d_set.tv_sec)+(now.tv_usec-d_set.tv_usec);