]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
More DTime cleanups, as suggested by Otto during review 9504/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 23 Sep 2020 08:29:26 +0000 (10:29 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 23 Sep 2020 08:29:26 +0000 (10:29 +0200)
pdns/misc.cc
pdns/misc.hh

index ef743a8e75172c25d6671655334870726aab9774..426a6d55594cbb47690df8c0b12a886f95a78386 100644 (file)
@@ -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)
index 488441912bac09c6c06dc52ee3d171d3a9ac11aa..5d4f528e8be85942293515df14f79ffb1dd0b878 100644 (file)
@@ -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);