]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: convert SBuf to C++11 initialization
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 2 Mar 2017 09:51:51 +0000 (22:51 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 2 Mar 2017 09:51:51 +0000 (22:51 +1300)
 Detected by Coverity Scan.

src/sbuf/SBuf.cc
src/sbuf/SBuf.h
src/sbuf/Stats.cc
src/sbuf/Stats.h
src/tests/stub_SBuf.cc

index d1f9b8697ea3e32c84c1dc9a64febe26e7ef955c..2cc50f1cfb74c4fa77c665ba04679dffd5eaf662 100644 (file)
@@ -36,8 +36,7 @@ SBufStats SBuf::stats;
 const SBuf::size_type SBuf::npos;
 const SBuf::size_type SBuf::maxSize;
 
-SBuf::SBuf()
-    : store_(GetStorePrototype()), off_(0), len_(0)
+SBuf::SBuf() : store_(GetStorePrototype())
 {
     debugs(24, 8, id << " created");
     ++stats.alloc;
@@ -53,8 +52,7 @@ SBuf::SBuf(const SBuf &S)
     ++stats.live;
 }
 
-SBuf::SBuf(const std::string &s)
-    : store_(GetStorePrototype()), off_(0), len_(0)
+SBuf::SBuf(const std::string &s) : store_(GetStorePrototype())
 {
     debugs(24, 8, id << " created from std::string");
     lowAppend(s.data(),s.length());
@@ -62,8 +60,7 @@ SBuf::SBuf(const std::string &s)
     ++stats.live;
 }
 
-SBuf::SBuf(const char *S, size_type n)
-    : store_(GetStorePrototype()), off_(0), len_(0)
+SBuf::SBuf(const char *S, size_type n) : store_(GetStorePrototype())
 {
     append(S,n);
     ++stats.alloc;
@@ -71,8 +68,7 @@ SBuf::SBuf(const char *S, size_type n)
     ++stats.live;
 }
 
-SBuf::SBuf(const char *S)
-    : store_(GetStorePrototype()), off_(0), len_(0)
+SBuf::SBuf(const char *S) : store_(GetStorePrototype())
 {
     append(S,npos);
     ++stats.alloc;
index a02257964e088296de5f648393f436f33aa54dd2..1cc4658e7ce41e6d4967942f2183163e27a5b3fc 100644 (file)
@@ -60,7 +60,7 @@ public:
 protected:
     SBufIterator(const SBuf &, size_type);
 
-    const char *iter;
+    const char *iter = nullptr;
 };
 
 /** Reverse input const_iterator for SBufs
@@ -98,14 +98,11 @@ public:
     /// create an empty (zero-size) SBuf
     SBuf();
     SBuf(const SBuf &S);
-#if __cplusplus >= 201103L
     SBuf(SBuf&& S) : store_(std::move(S.store_)), off_(S.off_), len_(S.len_) {
         ++stats.moves;
-        S.store_=NULL; //RefCount supports NULL, and S is about to be destructed
-        S.off_=0;
-        S.len_=0;
+        S.store_ = nullptr; //RefCount supports nullptr, and S is about to be destructed
+        S.off_ = S.len_ = 0;
     }
-#endif
 
     /** Constructor: import c-style string
      *
@@ -639,8 +636,8 @@ private:
     friend class Locker;
 
     MemBlob::Pointer store_; ///< memory block, possibly shared with other SBufs
-    size_type off_; ///< our content start offset from the beginning of shared store_
-    size_type len_; ///< number of our content bytes in shared store_
+    size_type off_ = 0; ///< our content start offset from the beginning of shared store_
+    size_type len_ = 0; ///< number of our content bytes in shared store_
     static SBufStats stats; ///< class-wide statistics
 
     /** obtain prototype store
index 63562373e48fa389253e2f8e4818199d9d63fa5f..7d20ab024ab27791f9641a5ec593ba4ec8c120a3 100644 (file)
 
 #include <iostream>
 
-SBufStats::SBufStats()
-    : alloc(0), allocCopy(0), allocFromCString(0),
-      assignFast(0), clear(0), append(0), moves(0), toStream(0), setChar(0),
-      getChar(0), compareSlow(0), compareFast(0), copyOut(0),
-      rawAccess(0), nulTerminate(0), chop(0), trim(0), find(0),
-      caseChange(0), cowFast(0), cowSlow(0), live(0)
-{}
-
 SBufStats&
 SBufStats::operator +=(const SBufStats& ss)
 {
index 00b76f047945c8f59fe492918d1d30d5513be9a6..7c280a58837d6927f42a3f94946088b44acadf1d 100644 (file)
 class SBufStats
 {
 public:
-    uint64_t alloc; ///<number of calls to SBuf constructors
-    uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
-    uint64_t allocFromCString; ///<number of copy-allocations from c-strings
-    uint64_t assignFast; ///<number of no-copy assignment operations
-    uint64_t clear; ///<number of clear operations
-    uint64_t append; ///<number of append operations
-    uint64_t moves; ///<number of move constructions/assignments
-    uint64_t toStream;  ///<number of write operations to ostreams
-    uint64_t setChar; ///<number of calls to setAt
-    uint64_t getChar; ///<number of calls to at() and operator[]
-    uint64_t compareSlow; ///<number of comparison operations requiring data scan
-    uint64_t compareFast; ///<number of comparison operations not requiring data scan
-    uint64_t copyOut; ///<number of data-copies to other forms of buffers
-    uint64_t rawAccess; ///<number of accesses to raw contents
-    uint64_t nulTerminate; ///<number of c_str() terminations
-    uint64_t chop;  ///<number of chop operations
-    uint64_t trim;  ///<number of trim operations
-    uint64_t find;  ///<number of find operations
-    uint64_t caseChange; ///<number of toUpper and toLower operations
-    uint64_t cowFast; ///<number of cow operations not actually requiring a copy
-    uint64_t cowSlow; ///<number of cow operations requiring a copy
-    uint64_t live;  ///<number of currently-allocated SBuf
-
     ///Dump statistics to an ostream.
     std::ostream& dump(std::ostream &os) const;
-    SBufStats();
 
     SBufStats& operator +=(const SBufStats&);
+
+public:
+    uint64_t alloc = 0; ///<number of calls to SBuf constructors
+    uint64_t allocCopy = 0; ///<number of calls to SBuf copy-constructor
+    uint64_t allocFromCString = 0; ///<number of copy-allocations from c-strings
+    uint64_t assignFast = 0; ///<number of no-copy assignment operations
+    uint64_t clear = 0; ///<number of clear operations
+    uint64_t append = 0; ///<number of append operations
+    uint64_t moves = 0; ///<number of move constructions/assignments
+    uint64_t toStream = 0;  ///<number of write operations to ostreams
+    uint64_t setChar = 0; ///<number of calls to setAt
+    uint64_t getChar = 0; ///<number of calls to at() and operator[]
+    uint64_t compareSlow = 0; ///<number of comparison operations requiring data scan
+    uint64_t compareFast = 0; ///<number of comparison operations not requiring data scan
+    uint64_t copyOut = 0; ///<number of data-copies to other forms of buffers
+    uint64_t rawAccess = 0; ///<number of accesses to raw contents
+    uint64_t nulTerminate = 0; ///<number of c_str() terminations
+    uint64_t chop = 0;  ///<number of chop operations
+    uint64_t trim = 0;  ///<number of trim operations
+    uint64_t find = 0;  ///<number of find operations
+    uint64_t caseChange = 0; ///<number of toUpper and toLower operations
+    uint64_t cowFast = 0; ///<number of cow operations not actually requiring a copy
+    uint64_t cowSlow = 0; ///<number of cow operations requiring a copy
+    uint64_t live = 0;  ///<number of currently-allocated SBuf
 };
 
 #endif /* SQUID_SBUF_STATS_H */
index e0904fad6c9e999e3daf46707405e0810c8c313b..d1bca7d84adaa396b943227a26affa783049a052 100644 (file)
@@ -19,7 +19,6 @@ SBufStats SBuf::stats;
 const SBuf::size_type SBuf::npos;
 const SBuf::size_type SBuf::maxSize;
 
-SBufStats::SBufStats() {}
 std::ostream& SBufStats::dump(std::ostream &os) const STUB_RETVAL(os)
 SBufStats& SBufStats::operator +=(const SBufStats&) STUB_RETVAL(*this)